Skip to content

Commit 44732c3

Browse files
Added endpoints for getting rules and events templates (#97)
1 parent b3d9242 commit 44732c3

11 files changed

+464
-102
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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.RestController;
8+
9+
10+
/**
11+
* No description
12+
* (Generated with springmvc-raml-parser v.0.10.11)
13+
*
14+
*/
15+
@RestController
16+
@RequestMapping(value = "/download", produces = "application/json")
17+
public interface DownloadController {
18+
19+
20+
/**
21+
* This call for getting list of available templates
22+
*
23+
*/
24+
@RequestMapping(value = "", method = RequestMethod.GET)
25+
public ResponseEntity<?> getDownload();
26+
27+
/**
28+
* This call for getting subscriptions template
29+
*
30+
*/
31+
@RequestMapping(value = "/subscriptionsTemplate", method = RequestMethod.GET)
32+
public ResponseEntity<?> getSubscriptionsTemplate();
33+
34+
/**
35+
* This call for getting rules template
36+
*
37+
*/
38+
@RequestMapping(value = "/rulesTemplate", method = RequestMethod.GET)
39+
public ResponseEntity<?> getRulesTemplate();
40+
41+
/**
42+
* This call for getting events template
43+
*
44+
*/
45+
@RequestMapping(value = "/eventsTemplate", method = RequestMethod.GET)
46+
public ResponseEntity<?> getEventsTemplate();
47+
48+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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 io.swagger.annotations.Api;
20+
import org.apache.commons.io.IOUtils;
21+
import org.json.JSONObject;
22+
import org.slf4j.Logger;
23+
import org.slf4j.LoggerFactory;
24+
import org.springframework.http.HttpStatus;
25+
import org.springframework.http.ResponseEntity;
26+
import org.springframework.stereotype.Component;
27+
import org.springframework.web.bind.annotation.CrossOrigin;
28+
29+
import java.io.IOException;
30+
import java.io.InputStream;
31+
32+
@Component
33+
@CrossOrigin
34+
@Api(value = "Get Templates", description = "REST endpoints for getting templates")
35+
public class DownloadControllerImpl implements DownloadController {
36+
37+
private static final Logger LOGGER = (Logger) LoggerFactory.getLogger(DownloadControllerImpl.class);
38+
39+
@Override
40+
public ResponseEntity<?> getDownload() {
41+
try {
42+
JSONObject response = new JSONObject();
43+
response.put("subscriptions", "/download/subscriptionsTemplate");
44+
response.put("rules", "/download/rulesTemplate");
45+
response.put("events", "/download/eventsTemplate");
46+
return new ResponseEntity<>(response.toString(), HttpStatus.OK);
47+
} catch (Exception e) {
48+
LOGGER.error(e.getMessage(), e);
49+
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
50+
}
51+
}
52+
53+
@Override
54+
public ResponseEntity<?> getSubscriptionsTemplate() {
55+
try {
56+
InputStream is = getClass().getResourceAsStream("/templates/subscriptionsTemplate.json");
57+
return new ResponseEntity<>(IOUtils.toByteArray(is), HttpStatus.OK);
58+
} catch (IOException e) {
59+
LOGGER.error(e.getMessage(), e);
60+
return new ResponseEntity<>("File is not found", HttpStatus.NOT_FOUND);
61+
} catch (Exception e) {
62+
LOGGER.error(e.getMessage(), e);
63+
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
64+
}
65+
}
66+
67+
@Override
68+
public ResponseEntity<?> getRulesTemplate() {
69+
try {
70+
InputStream is = getClass().getResourceAsStream("/templates/rulesTemplate.json");
71+
return new ResponseEntity<>(IOUtils.toByteArray(is), HttpStatus.OK);
72+
} catch (IOException e) {
73+
LOGGER.error(e.getMessage(), e);
74+
return new ResponseEntity<>("File is not found", HttpStatus.NOT_FOUND);
75+
} catch (Exception e) {
76+
LOGGER.error(e.getMessage(), e);
77+
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
78+
}
79+
}
80+
81+
@Override
82+
public ResponseEntity<?> getEventsTemplate() {
83+
try {
84+
InputStream is = getClass().getResourceAsStream("/templates/eventsTemplate.json");
85+
return new ResponseEntity<>(IOUtils.toByteArray(is), HttpStatus.OK);
86+
} catch (IOException e) {
87+
LOGGER.error(e.getMessage(), e);
88+
return new ResponseEntity<>("File is not found", HttpStatus.NOT_FOUND);
89+
} catch (Exception e) {
90+
LOGGER.error(e.getMessage(), e);
91+
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
92+
}
93+
}
94+
}

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
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+
*/
117
package com.ericsson.ei.controller;
218

319
import java.io.IOException;

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

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

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

Lines changed: 0 additions & 27 deletions
This file was deleted.
Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,30 @@
1-
/subscriptiontemplate:
2-
get:
3-
description: Subscription template
4-
responses:
5-
200:
6-
body:
7-
application/json:
1+
get:
2+
description: This call for getting list of available templates
3+
responses:
4+
200:
5+
body:
6+
application/string:
7+
8+
/subscriptionsTemplate:
9+
get:
10+
description: This call for getting subscriptions template
11+
responses:
12+
200:
13+
body:
14+
application/string:
15+
16+
/rulesTemplate:
17+
get:
18+
description: This call for getting rules template
19+
responses:
20+
200:
21+
body:
22+
application/string:
23+
24+
/eventsTemplate:
25+
get:
26+
description: This call for getting events template
27+
responses:
28+
200:
29+
body:
30+
application/string:

0 commit comments

Comments
 (0)