aboutsummaryrefslogtreecommitdiffstats
path: root/ms/sliboot/src/main/java
diff options
context:
space:
mode:
authorDan Timoney <dtimoney@att.com>2020-06-26 15:56:48 -0400
committerDan Timoney <dtimoney@att.com>2020-06-29 09:01:18 -0400
commit385874a6fd067cb17323a27ecd1af62b4176aecc (patch)
treeb6f02d6dca3f496aacff8ae29b1c0cca71b7b866 /ms/sliboot/src/main/java
parentf3430368211a5eb435a56a70006831255dcdba2e (diff)
Add RFC 8040 compliant error handler
Add a new error handler that formats error responses consistent with RFC 8040 (RESTCONF) standards. Change-Id: I67a6ab626d943115570f2e74d0a8132933726bc8 Issue-ID: CCSDK-2482 Signed-off-by: Dan Timoney <dtimoney@att.com>
Diffstat (limited to 'ms/sliboot/src/main/java')
-rw-r--r--ms/sliboot/src/main/java/org/onap/ccsdk/apps/ms/sliboot/App.java3
-rw-r--r--ms/sliboot/src/main/java/org/onap/ccsdk/apps/ms/sliboot/WebConfig.java3
-rw-r--r--ms/sliboot/src/main/java/org/onap/ccsdk/apps/ms/sliboot/controllers/RestconfApiController.java12
3 files changed, 12 insertions, 6 deletions
diff --git a/ms/sliboot/src/main/java/org/onap/ccsdk/apps/ms/sliboot/App.java b/ms/sliboot/src/main/java/org/onap/ccsdk/apps/ms/sliboot/App.java
index d2ef5e77..b93c2f9f 100644
--- a/ms/sliboot/src/main/java/org/onap/ccsdk/apps/ms/sliboot/App.java
+++ b/ms/sliboot/src/main/java/org/onap/ccsdk/apps/ms/sliboot/App.java
@@ -35,8 +35,7 @@ import org.onap.aaf.cadi.shiro.AAFRealm;
@SpringBootApplication
@EnableSwagger2
-@ComponentScan(basePackages = { "org.onap.ccsdk.apps.ms.sliboot.*" })
-
+@ComponentScan(basePackages = { "org.onap.ccsdk.apps.ms.sliboot.*", "org.onap.ccsdk.apps.services" })
public class App {
private static final Logger log = LoggerFactory.getLogger(App.class);
diff --git a/ms/sliboot/src/main/java/org/onap/ccsdk/apps/ms/sliboot/WebConfig.java b/ms/sliboot/src/main/java/org/onap/ccsdk/apps/ms/sliboot/WebConfig.java
index 3b0b2a20..1cef3161 100644
--- a/ms/sliboot/src/main/java/org/onap/ccsdk/apps/ms/sliboot/WebConfig.java
+++ b/ms/sliboot/src/main/java/org/onap/ccsdk/apps/ms/sliboot/WebConfig.java
@@ -28,10 +28,9 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
-@EnableWebMvc
@Configuration
@EnableJpaRepositories("org.onap.ccsdk.apps.ms.sliboot.*")
-@ComponentScan(basePackages = {"org.onap.ccsdk.apps.ms.sliboot.*"})
+@ComponentScan(basePackages = {"org.onap.ccsdk.apps.ms.sliboot.*", "org.onap.ccsdk.apps.services"})
@EntityScan("org.onap.ccsdk.apps.ms.sliboot.*")
@EnableTransactionManagement
public class WebConfig implements WebMvcConfigurer {
diff --git a/ms/sliboot/src/main/java/org/onap/ccsdk/apps/ms/sliboot/controllers/RestconfApiController.java b/ms/sliboot/src/main/java/org/onap/ccsdk/apps/ms/sliboot/controllers/RestconfApiController.java
index 4b78b2d1..f37fe137 100644
--- a/ms/sliboot/src/main/java/org/onap/ccsdk/apps/ms/sliboot/controllers/RestconfApiController.java
+++ b/ms/sliboot/src/main/java/org/onap/ccsdk/apps/ms/sliboot/controllers/RestconfApiController.java
@@ -29,6 +29,9 @@ import org.onap.ccsdk.apps.ms.sliboot.swagger.OperationalApi;
import org.onap.ccsdk.apps.ms.sliboot.swagger.OperationsApi;
import org.onap.ccsdk.apps.ms.sliboot.data.TestResultsOperationalRepository;
import org.onap.ccsdk.apps.ms.sliboot.swagger.model.*;
+import org.onap.ccsdk.apps.services.RestApplicationException;
+import org.onap.ccsdk.apps.services.RestException;
+import org.onap.ccsdk.apps.services.RestProtocolException;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
import org.onap.ccsdk.sli.core.sli.SvcLogicException;
import org.onap.ccsdk.sli.core.sli.provider.base.SvcLogicServiceBase;
@@ -42,6 +45,7 @@ import org.springframework.context.annotation.ComponentScan;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
@@ -49,7 +53,7 @@ import java.util.*;
@javax.annotation.Generated(value = "io.swagger.codegen.languages.SpringCodegen", date = "2020-02-20T12:50:11.207-05:00")
-@Controller
+@RestController
@ComponentScan(basePackages = {"org.onap.ccsdk.apps.ms.sliboot.*", "org.onap.ccsdk.apps.services"})
@EntityScan("org.onap.ccsdk.apps.ms.sliboot.*")
public class RestconfApiController implements ConfigApi, OperationalApi, OperationsApi {
@@ -273,7 +277,7 @@ public class RestconfApiController implements ConfigApi, OperationalApi, Operati
}
@Override
- public ResponseEntity<SliApiTestResults> configSLIAPItestResultsGet() {
+ public ResponseEntity<SliApiTestResults> configSLIAPItestResultsGet() throws RestException {
if(getObjectMapper().isPresent() && getAcceptHeader().isPresent()) {
} else {
@@ -282,6 +286,10 @@ public class RestconfApiController implements ConfigApi, OperationalApi, Operati
SliApiTestResults results = new SliApiTestResults();
+ if (testResultsConfigRepository.count() == 0) {
+ throw new RestApplicationException("data-missing", "Request could not be completed because the relevant data model content does not exist", 404);
+ }
+
testResultsConfigRepository.findAll().forEach(testResult -> {
SliApiTestresultsTestResult item = null;
try {