Skip to content

Commit 09dff54

Browse files
authored
[DURACI-6698]- Implement query service (#21)
1 parent 9570e53 commit 09dff54

18 files changed

+863
-63
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
<java.version>1.8</java.version>
1717
<plugin-version>0.10.11</plugin-version>
1818
<output-relative-path>src/main/java</output-relative-path>
19-
<raml-path>src/main/resources/public/raml/subscription.raml</raml-path>
2019
<raml-path>src/main/resources/public/raml/instance_info.raml</raml-path>
20+
<raml-path>src/main/resources/public/raml/eiffel-intelligence.raml</raml-path>
2121
<base-package>com.ericsson.ei.controller</base-package>
2222
</properties>
2323

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
package com.ericsson.ei.controller;
3+
4+
import com.ericsson.ei.controller.model.QueryResponse;
5+
import org.springframework.http.ResponseEntity;
6+
import org.springframework.web.bind.annotation.RequestMapping;
7+
import org.springframework.web.bind.annotation.RequestMethod;
8+
import org.springframework.web.bind.annotation.RequestParam;
9+
import org.springframework.web.bind.annotation.RestController;
10+
11+
12+
/**
13+
* No description
14+
* (Generated with springmvc-raml-parser v.0.8.6)
15+
*
16+
*/
17+
@RestController
18+
@RequestMapping(value = "/query/aggregatedObject", produces = "application/json")
19+
public interface AggregatedObjectController {
20+
21+
22+
/**
23+
* No description
24+
*
25+
*/
26+
@RequestMapping(value = "", method = RequestMethod.GET)
27+
public ResponseEntity<QueryResponse> getQueryAggregatedObject(
28+
@RequestParam
29+
String id);
30+
31+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
Copyright 2017 Ericsson AB.
3+
For a full list of individual contributors, please see the commit history.
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
Unless required by applicable law or agreed to in writing, software
9+
distributed under the License is distributed on an "AS IS" BASIS,
10+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
See the License for the specific language governing permissions and
12+
limitations under the License.
13+
*/
14+
package com.ericsson.ei.controller;
15+
16+
import java.util.ArrayList;
17+
18+
import org.slf4j.Logger;
19+
import org.slf4j.LoggerFactory;
20+
import org.springframework.beans.factory.annotation.Autowired;
21+
import org.springframework.http.HttpStatus;
22+
import org.springframework.http.ResponseEntity;
23+
import org.springframework.stereotype.Component;
24+
import org.springframework.web.bind.annotation.CrossOrigin;
25+
import org.springframework.web.bind.annotation.RequestParam;
26+
27+
import com.ericsson.ei.controller.model.QueryResponse;
28+
import com.ericsson.ei.queryservice.ProcessAggregatedObject;
29+
30+
/**
31+
* This class represents the REST GET mechanism to extract the aggregated data
32+
* on the basis of the ID from the aggregatedObject.
33+
*
34+
*/
35+
@Component
36+
@CrossOrigin
37+
public class AggregatedObjectControllerImpl implements AggregatedObjectController {
38+
39+
static Logger log = (Logger) LoggerFactory.getLogger(AggregatedObjectControllerImpl.class);
40+
41+
@Autowired
42+
private ProcessAggregatedObject processAggregatedObject;
43+
44+
/**
45+
* This method is responsible for the REST Get mechanism to extract the
46+
* aggregated data on the basis of the ID from the aggregatedObject.
47+
*
48+
* @param id
49+
* @return ResponseEntity
50+
*/
51+
public ResponseEntity<QueryResponse> getQueryAggregatedObject(@RequestParam("ID") final String id) {
52+
ArrayList<String> response = processAggregatedObject.processQueryAggregatedObject(id);
53+
log.info("The response is : " + response.toString());
54+
return new ResponseEntity(response.toString(), HttpStatus.OK);
55+
}
56+
57+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
package com.ericsson.ei.controller;
3+
4+
import com.ericsson.ei.controller.model.QueryResponse;
5+
import org.springframework.http.ResponseEntity;
6+
import org.springframework.web.bind.annotation.RequestMapping;
7+
import org.springframework.web.bind.annotation.RequestMethod;
8+
import org.springframework.web.bind.annotation.RequestParam;
9+
import org.springframework.web.bind.annotation.RestController;
10+
11+
12+
/**
13+
* No description
14+
* (Generated with springmvc-raml-parser v.0.8.6)
15+
*
16+
*/
17+
@RestController
18+
@RequestMapping(value = "/query/missedNotifications", produces = "application/json")
19+
public interface MissedNotificationController {
20+
21+
22+
/**
23+
* List the missed notification based on the subscriptionName in the query parameter.
24+
*
25+
*/
26+
@RequestMapping(value = "", method = RequestMethod.GET)
27+
public ResponseEntity<QueryResponse> getQueryMissedNotifications(
28+
@RequestParam
29+
String subscriptionName);
30+
31+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
Copyright 2017 Ericsson AB.
3+
For a full list of individual contributors, please see the commit history.
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
Unless required by applicable law or agreed to in writing, software
9+
distributed under the License is distributed on an "AS IS" BASIS,
10+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
See the License for the specific language governing permissions and
12+
limitations under the License.
13+
*/
14+
package com.ericsson.ei.controller;
15+
16+
import java.util.ArrayList;
17+
18+
import org.slf4j.Logger;
19+
import org.slf4j.LoggerFactory;
20+
import org.springframework.beans.factory.annotation.Autowired;
21+
import org.springframework.http.HttpStatus;
22+
import org.springframework.http.ResponseEntity;
23+
import org.springframework.stereotype.Component;
24+
import org.springframework.web.bind.annotation.CrossOrigin;
25+
import org.springframework.web.bind.annotation.RequestParam;
26+
27+
import com.ericsson.ei.controller.model.QueryResponse;
28+
import com.ericsson.ei.queryservice.ProcessMissedNotification;
29+
30+
/**
31+
* This class represents the REST GET mechanism to extract the aggregated data
32+
* on the basis of the SubscriptionName from the Missed Notification Object.
33+
*
34+
*/
35+
@Component
36+
@CrossOrigin
37+
public class MissedNotificationControllerImpl implements MissedNotificationController {
38+
39+
static Logger log = (Logger) LoggerFactory.getLogger(MissedNotificationControllerImpl.class);
40+
41+
@Autowired
42+
private ProcessMissedNotification processMissedNotification;
43+
44+
/**
45+
* This method is responsible for the REST GET mechanism to extract the data
46+
* on the basis of the SubscriptionName from the Missed Notification Object.
47+
*
48+
* @param subscriptionName
49+
* @return ResponseEntity
50+
*/
51+
public ResponseEntity<QueryResponse> getQueryMissedNotifications(
52+
@RequestParam("SubscriptionName") final String subscriptionName) {
53+
ArrayList response = processMissedNotification.processQueryMissedNotification(subscriptionName);
54+
log.info("The response is : " + response.toString());
55+
return new ResponseEntity(response.toString(), HttpStatus.OK);
56+
}
57+
58+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
2+
package com.ericsson.ei.controller.model;
3+
4+
import java.util.HashMap;
5+
import java.util.Map;
6+
7+
import org.apache.commons.lang3.builder.EqualsBuilder;
8+
import org.apache.commons.lang3.builder.HashCodeBuilder;
9+
import org.apache.commons.lang3.builder.ToStringBuilder;
10+
11+
import com.fasterxml.jackson.annotation.JsonAnyGetter;
12+
import com.fasterxml.jackson.annotation.JsonAnySetter;
13+
import com.fasterxml.jackson.annotation.JsonIgnore;
14+
import com.fasterxml.jackson.annotation.JsonInclude;
15+
import com.fasterxml.jackson.annotation.JsonProperty;
16+
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
17+
18+
@JsonInclude(JsonInclude.Include.NON_NULL)
19+
@JsonPropertyOrder({ "responseEntity" })
20+
public class QueryResponse {
21+
22+
@JsonProperty("responseEntity")
23+
private String responseEntity;
24+
@JsonIgnore
25+
private Map<String, Object> additionalProperties = new HashMap<String, Object>();
26+
27+
/**
28+
*
29+
* @return The responseEntity
30+
*/
31+
@JsonProperty("responseEntity")
32+
public String getResponseEntity() {
33+
return responseEntity;
34+
}
35+
36+
/**
37+
*
38+
* @param responseEntity
39+
* The responseEntity
40+
*/
41+
@JsonProperty("responseEntity")
42+
public void setResponseEntity(String responseEntity) {
43+
this.responseEntity = responseEntity;
44+
}
45+
46+
@Override
47+
public String toString() {
48+
return ToStringBuilder.reflectionToString(this);
49+
}
50+
51+
@JsonAnyGetter
52+
public Map<String, Object> getAdditionalProperties() {
53+
return this.additionalProperties;
54+
}
55+
56+
@JsonAnySetter
57+
public void setAdditionalProperty(String name, Object value) {
58+
this.additionalProperties.put(name, value);
59+
}
60+
61+
@Override
62+
public int hashCode() {
63+
return new HashCodeBuilder().append(responseEntity).append(additionalProperties).toHashCode();
64+
}
65+
66+
@Override
67+
public boolean equals(Object other) {
68+
if (other == this) {
69+
return true;
70+
}
71+
if ((other instanceof QueryResponse) == false) {
72+
return false;
73+
}
74+
QueryResponse rhs = ((QueryResponse) other);
75+
return new EqualsBuilder().append(responseEntity, rhs.responseEntity)
76+
.append(additionalProperties, rhs.additionalProperties).isEquals();
77+
}
78+
79+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
Copyright 2017 Ericsson AB.
3+
For a full list of individual contributors, please see the commit history.
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
Unless required by applicable law or agreed to in writing, software
9+
distributed under the License is distributed on an "AS IS" BASIS,
10+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
See the License for the specific language governing permissions and
12+
limitations under the License.
13+
*/
14+
package com.ericsson.ei.queryservice;
15+
16+
import java.util.ArrayList;
17+
18+
import javax.annotation.PostConstruct;
19+
20+
import org.slf4j.Logger;
21+
import org.slf4j.LoggerFactory;
22+
import org.springframework.beans.factory.annotation.Autowired;
23+
import org.springframework.beans.factory.annotation.Value;
24+
import org.springframework.stereotype.Component;
25+
26+
import com.ericsson.ei.mongodbhandler.MongoDBHandler;
27+
import com.fasterxml.jackson.databind.JsonNode;
28+
import com.fasterxml.jackson.databind.ObjectMapper;
29+
30+
/**
31+
* This class represents the mechanism to extract the aggregated data on the
32+
* basis of the ID from the aggregatedObject.
33+
*
34+
*
35+
*/
36+
@Component
37+
public class ProcessAggregatedObject {
38+
39+
@Value("${aggregated.collection.name}")
40+
private String aggregationCollectionName;
41+
42+
@Value("${database.name}")
43+
private String aggregationDataBaseName;
44+
45+
static Logger log = (Logger) LoggerFactory.getLogger(ProcessAggregatedObject.class);
46+
47+
@Autowired
48+
MongoDBHandler handler;
49+
50+
/**
51+
* The method is responsible to extract the aggregated data on the basis of
52+
* the ID from the aggregatedObject.
53+
*
54+
* @param id
55+
* @return ArrayList
56+
*/
57+
public ArrayList<String> processQueryAggregatedObject(String id) {
58+
ObjectMapper mapper = new ObjectMapper();
59+
String condition = "{\"id\" : \"" + id + "\"}";
60+
log.info("The condition is : " + condition);
61+
JsonNode jsonCondition = null;
62+
try {
63+
jsonCondition = mapper.readTree(condition);
64+
} catch (Exception e) {
65+
log.error(e.getMessage(), e);
66+
}
67+
log.info("The Json condition is : " + jsonCondition);
68+
ArrayList<String> response = handler.find(aggregationDataBaseName, aggregationCollectionName,
69+
jsonCondition.toString());
70+
return response;
71+
}
72+
73+
@PostConstruct
74+
public void init() {
75+
log.debug("The Aggregated Database is : " + aggregationDataBaseName);
76+
log.debug("The Aggregated Collection is : " + aggregationCollectionName);
77+
}
78+
79+
}

0 commit comments

Comments
 (0)