Skip to content

Commit c489bc7

Browse files
saif-ericssonvasile-baluta
authored andcommitted
JMESPath REST API (#43)
Add REST API to JMESPath functionality
1 parent 0992780 commit c489bc7

22 files changed

+395
-295
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ target/
1717

1818
# Others
1919
derby.log
20+
work/
2021

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
/**
1313
* No description
14-
* (Generated with springmvc-raml-parser v.0.8.6)
14+
* (Generated with springmvc-raml-parser v.0.10.11)
1515
*
1616
*/
1717
@RestController

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
/**
1313
* No description
14-
* (Generated with springmvc-raml-parser v.0.8.6)
14+
* (Generated with springmvc-raml-parser v.0.10.11)
1515
*
1616
*/
1717
@RestController

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ public class MissedNotificationControllerImpl implements MissedNotificationContr
4242
private ProcessMissedNotification processMissedNotification;
4343

4444
/**
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.
45+
* This method is responsible for the REST GET mechanism to extract the data on
46+
* the basis of the SubscriptionName from the Missed Notification Object.
4747
*
4848
* @param subscriptionName
4949
* @return ResponseEntity
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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 = "/jmespathrule/ruleCheck", produces = "application/json")
18+
public interface RuleCheckController {
19+
20+
21+
/**
22+
* No description
23+
*
24+
*/
25+
@RequestMapping(value = "", method = RequestMethod.POST)
26+
public ResponseEntity<?> updateJmespathruleRuleCheck(
27+
@RequestParam
28+
String rule,
29+
@RequestParam
30+
String jsonContent);
31+
32+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package com.ericsson.ei.controller;
2+
3+
import org.json.JSONObject;
4+
import org.slf4j.Logger;
5+
import org.slf4j.LoggerFactory;
6+
import org.springframework.beans.factory.annotation.Autowired;
7+
import org.springframework.http.HttpStatus;
8+
import org.springframework.http.ResponseEntity;
9+
import org.springframework.stereotype.Component;
10+
import org.springframework.web.bind.annotation.CrossOrigin;
11+
import org.springframework.web.bind.annotation.RequestMapping;
12+
import org.springframework.web.bind.annotation.RequestMethod;
13+
14+
import com.ericsson.ei.jmespath.JmesPathInterface;
15+
16+
import io.swagger.annotations.Api;
17+
import io.swagger.annotations.ApiOperation;
18+
19+
/**
20+
* This class implements the Interface for JMESPath API, generated by RAML 0.8
21+
* Provides interaction with JmesPathInterface class
22+
*
23+
* Usage: 1. If input contains a rule as an argument and json expression in a
24+
* text file, then the following curl command may be used. curl -H
25+
* "Content-type: application/x-www-form-urlencoded" -X POST --data-urlencode
26+
* jsonContent@testjson.txt
27+
* http://localhost:8090/jmespathrule/runRule?rule=data.outcome
28+
*
29+
* 2. If input contains rule and json expression as two String arguments, then
30+
* the following curl command may be used. curl -H "Content-type:
31+
* application/x-www-form-urlencoded" -X POST -d
32+
* jsonContent={"data":{"outcome":{"conclusion":"SUCCESSFUL"},"test":"persistentLogs"}}
33+
* http://localhost:8090/jmespathrule/runRule?rule=data.outcome
34+
*
35+
*/
36+
37+
@Component
38+
@CrossOrigin
39+
@Api(value = "jmespath")
40+
@RequestMapping(value = "/jmespathrule/ruleCheck", produces = "application/json")
41+
public class RuleCheckControllerImpl implements RuleCheckController {
42+
43+
private static final Logger LOG = LoggerFactory.getLogger(SubscriptionControllerImpl.class);
44+
45+
@Autowired
46+
JmesPathInterface jmesPathInterface;
47+
48+
/**
49+
* This method interacts with JmesPathInterface class method runRuleOnEvent to
50+
* evaluate a rule on JSON object.
51+
*
52+
* @param rule-
53+
* takes a String as a rule that need to be evaluated on JSON content
54+
* @param jsonContent-
55+
* takes JSON object as a String
56+
* @return return a String object
57+
*
58+
*/
59+
@Override
60+
@CrossOrigin
61+
@ApiOperation(value = "run rule on event")
62+
@RequestMapping(value = "", method = RequestMethod.POST)
63+
public ResponseEntity<?> updateJmespathruleRuleCheck(String rule, String jsonContent) {
64+
String res = new String("[]");
65+
66+
try {
67+
JSONObject jsonObj = new JSONObject(jsonContent);
68+
String jsonString = jsonObj.toString();
69+
res = jmesPathInterface.runRuleOnEvent(rule, jsonString).toString();
70+
LOG.info("Query :" + rule + " executed Successfully");
71+
return new ResponseEntity<String>(res, HttpStatus.OK);
72+
73+
} catch (Exception e) {
74+
LOG.error(e.getMessage(), e);
75+
return new ResponseEntity<String>(res, HttpStatus.BAD_REQUEST);
76+
}
77+
}
78+
79+
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
/**
1313
* Provides interaction with Subscription resource
14-
* (Generated with springmvc-raml-parser v.0.8.6)
14+
* (Generated with springmvc-raml-parser v.0.10.11)
1515
*
1616
*/
1717
@RestController
@@ -52,7 +52,7 @@ public ResponseEntity<com.ericsson.ei.controller.model.SubscriptionResponse> upd
5252
*/
5353
@RequestMapping(value = "/{subscriptionName}", method = RequestMethod.GET)
5454
public ResponseEntity<List<com.ericsson.ei.controller.model.Subscription>> getSubscriptionById(
55-
@PathVariable
55+
@PathVariable(required = false)
5656
String subscriptionName);
5757

5858
/**
@@ -61,7 +61,7 @@ public ResponseEntity<List<com.ericsson.ei.controller.model.Subscription>> getSu
6161
*/
6262
@RequestMapping(value = "/{subscriptionName}", method = RequestMethod.DELETE)
6363
public ResponseEntity<com.ericsson.ei.controller.model.SubscriptionResponse> deleteSubscriptionById(
64-
@PathVariable
64+
@PathVariable(required = false)
6565
String subscriptionName);
6666

6767
}

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

Lines changed: 47 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,14 @@
4343
@CrossOrigin
4444
@Api(value = "subscription", description = "The Subscription API for the store and retrieve the subscriptions from the database")
4545
public class SubscriptionControllerImpl implements SubscriptionController {
46-
46+
4747
@Autowired
4848
private ISubscriptionService subscriptionService;
49-
49+
5050
private SubscriptionValidator subscriptionValidator = new SubscriptionValidator();
51-
51+
5252
private static final Logger LOG = LoggerFactory.getLogger(SubscriptionControllerImpl.class);
53-
54-
53+
5554
@Override
5655
@CrossOrigin
5756
@ApiOperation(value = "Creates the subscription")
@@ -60,80 +59,84 @@ public ResponseEntity<SubscriptionResponse> createSubscription(@RequestBody Subs
6059

6160
try {
6261
subscriptionValidator.validateSubscription(subscription);
62+
} catch (SubscriptionValidationException e) {
63+
String msg = "Validation of Subscription parameters on:" + subscription.getSubscriptionName()
64+
+ " failed! Error: " + e.getMessage();
65+
LOG.error(msg);
66+
subscriptionResponse.setMsg(msg);
67+
subscriptionResponse.setStatusCode(HttpStatus.PRECONDITION_FAILED.value());
68+
return new ResponseEntity<SubscriptionResponse>(subscriptionResponse, HttpStatus.PRECONDITION_FAILED);
6369
}
64-
catch (SubscriptionValidationException e) {
65-
String msg = "Validation of Subscription parameters on:" + subscription.getSubscriptionName() +
66-
" failed! Error: " + e.getMessage();
67-
LOG.error(msg);
68-
subscriptionResponse.setMsg(msg); subscriptionResponse.setStatusCode(HttpStatus.PRECONDITION_FAILED.value());
69-
return new ResponseEntity<SubscriptionResponse>(subscriptionResponse, HttpStatus.PRECONDITION_FAILED);
70-
}
71-
70+
7271
if (!subscriptionService.doSubscriptionExist(subscription.getSubscriptionName())) {
7372
subscriptionService.addSubscription(subscription);
7473
LOG.info("Subscription :" + subscription.getSubscriptionName() + " Inserted Successfully");
75-
subscriptionResponse.setMsg("Inserted Successfully"); subscriptionResponse.setStatusCode(HttpStatus.OK.value());
74+
subscriptionResponse.setMsg("Inserted Successfully");
75+
subscriptionResponse.setStatusCode(HttpStatus.OK.value());
7676
return new ResponseEntity<SubscriptionResponse>(subscriptionResponse, HttpStatus.OK);
7777
} else {
7878
LOG.error("Subscription :" + subscription.getSubscriptionName() + " already exists");
79-
subscriptionResponse.setMsg("Subscription already exists"); subscriptionResponse.setStatusCode(HttpStatus.BAD_REQUEST.value());
79+
subscriptionResponse.setMsg("Subscription already exists");
80+
subscriptionResponse.setStatusCode(HttpStatus.BAD_REQUEST.value());
8081
return new ResponseEntity<SubscriptionResponse>(subscriptionResponse, HttpStatus.BAD_REQUEST);
8182
}
82-
83+
8384
}
84-
85+
8586
@Override
8687
@CrossOrigin
8788
@ApiOperation(value = "Returns the subscription rules for given subscription name")
8889
public ResponseEntity<List<Subscription>> getSubscriptionById(@PathVariable String subscriptionName) {
89-
List<Subscription> subscriptionList = new ArrayList<Subscription>();
90+
List<Subscription> subscriptionList = new ArrayList<Subscription>();
9091
try {
9192
LOG.info("Subscription :" + subscriptionName + " fetch started");
9293
subscriptionList.add(subscriptionService.getSubscription(subscriptionName));
9394
LOG.info("Subscription :" + subscriptionName + " fetched");
94-
return new ResponseEntity<List<Subscription>> (subscriptionList, HttpStatus.OK);
95+
return new ResponseEntity<List<Subscription>>(subscriptionList, HttpStatus.OK);
9596
} catch (SubscriptionNotFoundException e) {
9697
LOG.error("Subscription :" + subscriptionName + " not found in records");
97-
return new ResponseEntity<List<Subscription>> (subscriptionList, HttpStatus.OK);
98-
98+
return new ResponseEntity<List<Subscription>>(subscriptionList, HttpStatus.OK);
99+
99100
}
100-
101+
101102
}
102-
103+
103104
@Override
104105

105-
//@CrossOrigin
106+
// @CrossOrigin
106107
@ApiOperation(value = "Update the existing subscription by the subscription name")
107108
public ResponseEntity<SubscriptionResponse> updateSubscriptions(@RequestBody Subscription subscription) {
108-
String subscriptionName = subscription.getSubscriptionName();
109+
String subscriptionName = subscription.getSubscriptionName();
109110
LOG.info("Subscription :" + subscriptionName + " update started");
110111
SubscriptionResponse subscriptionResponse = new SubscriptionResponse();
111112

112113
try {
113114
subscriptionValidator.validateSubscription(subscription);
115+
} catch (SubscriptionValidationException e) {
116+
String msg = "Validation of Subscription parameters on:" + subscription.getSubscriptionName()
117+
+ " failed! Error: " + e.getMessage();
118+
LOG.error(msg);
119+
subscriptionResponse.setMsg(msg);
120+
subscriptionResponse.setStatusCode(HttpStatus.PRECONDITION_FAILED.value());
121+
return new ResponseEntity<SubscriptionResponse>(subscriptionResponse, HttpStatus.PRECONDITION_FAILED);
114122
}
115-
catch (SubscriptionValidationException e) {
116-
String msg = "Validation of Subscription parameters on:" + subscription.getSubscriptionName() +
117-
" failed! Error: " + e.getMessage();
118-
LOG.error(msg);
119-
subscriptionResponse.setMsg(msg); subscriptionResponse.setStatusCode(HttpStatus.PRECONDITION_FAILED.value());
120-
return new ResponseEntity<SubscriptionResponse>(subscriptionResponse, HttpStatus.PRECONDITION_FAILED);
121-
}
122-
123+
123124
if (subscriptionService.doSubscriptionExist(subscriptionName)) {
124125
subscriptionService.modifySubscription(subscription, subscriptionName);
125126
LOG.info("Subscription :" + subscriptionName + " update completed");
126-
subscriptionResponse.setMsg("Updated Successfully"); subscriptionResponse.setStatusCode(HttpStatus.OK.value());
127+
subscriptionResponse.setMsg("Updated Successfully");
128+
subscriptionResponse.setStatusCode(HttpStatus.OK.value());
127129
return new ResponseEntity<SubscriptionResponse>(subscriptionResponse, HttpStatus.OK);
128-
130+
129131
} else {
130132
LOG.error("Subscription :" + subscription.getSubscriptionName() + " can't be found.");
131-
subscriptionResponse.setMsg("Subscription can't be found"); subscriptionResponse.setStatusCode(HttpStatus.BAD_REQUEST.value());
133+
subscriptionResponse.setMsg("Subscription can't be found");
134+
subscriptionResponse.setStatusCode(HttpStatus.BAD_REQUEST.value());
132135
return new ResponseEntity<SubscriptionResponse>(subscriptionResponse, HttpStatus.BAD_REQUEST);
133136
}
134-
137+
135138
}
136-
139+
137140
@Override
138141
@CrossOrigin
139142
@ApiOperation(value = "Removes the subscription from the database")
@@ -142,16 +145,18 @@ public ResponseEntity<SubscriptionResponse> deleteSubscriptionById(@PathVariable
142145
LOG.info("Subscription :" + subscriptionName + " delete started");
143146
if (subscriptionService.deleteSubscription(subscriptionName)) {
144147
LOG.info("Subscription :" + subscriptionName + " deleted Successfully");
145-
subscriptionResponse.setMsg("Deleted Successfully"); subscriptionResponse.setStatusCode(HttpStatus.OK.value());
148+
subscriptionResponse.setMsg("Deleted Successfully");
149+
subscriptionResponse.setStatusCode(HttpStatus.OK.value());
146150
return new ResponseEntity<SubscriptionResponse>(subscriptionResponse, HttpStatus.OK);
147151
} else {
148152
LOG.info("Subscription :" + subscriptionName + " delete completed :: Record not found for delete");
149-
subscriptionResponse.setMsg("Record not found for delete"); subscriptionResponse.setStatusCode(HttpStatus.BAD_REQUEST.value());
153+
subscriptionResponse.setMsg("Record not found for delete");
154+
subscriptionResponse.setStatusCode(HttpStatus.BAD_REQUEST.value());
150155
return new ResponseEntity<SubscriptionResponse>(subscriptionResponse, HttpStatus.BAD_REQUEST);
151156
}
152-
157+
153158
}
154-
159+
155160
@Override
156161
@CrossOrigin
157162
@ApiOperation(value = "Retrieve all the subscriptions")

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,11 @@ public class Condition {
2424
@JsonIgnore
2525
private Map<String, Object> additionalProperties = new HashMap<String, Object>();
2626

27-
/**
28-
*
29-
* @return
30-
* The jmespath
31-
*/
3227
@JsonProperty("jmespath")
3328
public String getJmespath() {
3429
return jmespath;
3530
}
3631

37-
/**
38-
*
39-
* @param jmespath
40-
* The jmespath
41-
*/
4232
@JsonProperty("jmespath")
4333
public void setJmespath(String jmespath) {
4434
this.jmespath = jmespath;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.fasterxml.jackson.annotation.JsonIgnore;
99
import com.fasterxml.jackson.annotation.JsonInclude;
1010
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
11+
1112
import org.apache.commons.lang3.builder.EqualsBuilder;
1213
import org.apache.commons.lang3.builder.HashCodeBuilder;
1314
import org.apache.commons.lang3.builder.ToStringBuilder;

0 commit comments

Comments
 (0)