Revise controller error handling
[portal/ric-dashboard.git] / webapp-backend / src / main / java / org / oransc / ric / portal / dashboard / controller / AnrXappController.java
index c6a6b90..ae6845b 100644 (file)
@@ -36,6 +36,7 @@ import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.http.MediaType;
+import org.springframework.security.access.annotation.Secured;
 import org.springframework.util.Assert;
 import org.springframework.web.bind.annotation.DeleteMapping;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -49,8 +50,13 @@ import org.springframework.web.bind.annotation.RestController;
 import io.swagger.annotations.ApiOperation;
 
 /**
- * Provides methods to contact the ANR xApp which manages a Neighbor Cell
- * Relation Table (NCRT).
+ * Proxies calls from the front end to the ANR xApp, which manages a Neighbor
+ * Cell Relation Table (NCRT).
+ * 
+ * If a method throws RestClientResponseException, it is handled by
+ * {@link CustomResponseEntityExceptionHandler#handleProxyMethodException(Exception, org.springframework.web.context.request.WebRequest)}
+ * which returns status 502. All other exceptions are handled by Spring which
+ * returns status 500.
  */
 @Configuration
 @RestController
@@ -71,10 +77,6 @@ public class AnrXappController {
        // Path parameters
        public static final String PP_SERVING = "servingcells";
        public static final String PP_NEIGHBOR = "neighborcells";
-       // Query parameters
-       public static final String QP_NODEB = "ggnodeb";
-       public static final String QP_SERVING = "servingCellNrcgi";
-       public static final String QP_NEIGHBOR = "neighborCellNrpci";
 
        // Populated by the autowired constructor
        private final HealthApi healthApi;
@@ -93,12 +95,14 @@ public class AnrXappController {
 
        @ApiOperation(value = "Gets the ANR client library MANIFEST.MF property Implementation-Version.", response = SuccessTransport.class)
        @GetMapping(VERSION_METHOD)
+       // No role required
        public SuccessTransport getClientVersion() {
                return new SuccessTransport(200, DashboardApplication.getImplementationVersion(HealthApi.class));
        }
 
        @ApiOperation(value = "Performs a liveness probe on the ANR xApp, result expressed as the response code.")
        @GetMapping(HEALTH_ALIVE_METHOD)
+       // No role required
        public void getHealthAlive(HttpServletResponse response) {
                logger.debug("getHealthAlive");
                healthApi.getHealthAlive();
@@ -107,6 +111,7 @@ public class AnrXappController {
 
        @ApiOperation(value = "Performs a readiness probe on the ANR xApp, result expressed as the response code.")
        @GetMapping(HEALTH_READY_METHOD)
+       // No role required
        public void getHealthReady(HttpServletResponse response) {
                logger.debug("getHealthReady");
                healthApi.getHealthReady();
@@ -115,6 +120,7 @@ public class AnrXappController {
 
        @ApiOperation(value = "Returns list of gNodeB IDs based on NCRT in ANR", response = GgNodeBTable.class)
        @GetMapping(GNODEBS_METHOD)
+       @Secured({ DashboardConstants.ROLE_ADMIN, DashboardConstants.ROLE_STANDARD })
        public GgNodeBTable getGnodebs() {
                logger.debug("getGnodebs");
                return ncrtApi.getgNodeB();
@@ -122,18 +128,20 @@ public class AnrXappController {
 
        @ApiOperation(value = "Returns neighbor cell relation table for all gNodeBs or based on query parameters", response = NeighborCellRelationTable.class)
        @GetMapping(NCRT_METHOD)
+       @Secured({ DashboardConstants.ROLE_ADMIN, DashboardConstants.ROLE_STANDARD })
        public NeighborCellRelationTable getNcrt( //
-                       @RequestParam(name = QP_NODEB, required = false) String ggnbId, //
-                       @RequestParam(name = QP_SERVING, required = false) String servingCellNrcgi, //
-                       @RequestParam(name = QP_NEIGHBOR, required = false) String neighborCellNrpci) {
-               logger.debug("getNcrt: ggnbid {}, servingCellNrpci {}, neighborCellNrcgi {}", ggnbId, servingCellNrcgi,
+                       @RequestParam(required = false) String ggnodeb, //
+                       @RequestParam(required = false) String servingCellNrcgi, //
+                       @RequestParam(required = false) String neighborCellNrpci) {
+               logger.debug("getNcrt: ggnbid {}, servingCellNrpci {}, neighborCellNrcgi {}", ggnodeb, servingCellNrcgi,
                                neighborCellNrpci);
-               return ncrtApi.getNcrt(ggnbId, servingCellNrcgi, neighborCellNrpci);
+               return ncrtApi.getNcrt(ggnodeb, servingCellNrcgi, neighborCellNrpci);
        }
 
        // /ncrt/servingcells/{servCellNrcgi}/neighborcells/{neighCellNrpci} :
        @ApiOperation(value = "Modify neighbor cell relation based on Serving Cell NRCGI and Neighbor Cell NRPCI")
        @PutMapping(NCRT_METHOD + "/" + PP_SERVING + "/{" + PP_SERVING + "}/" + PP_NEIGHBOR + "/{" + PP_NEIGHBOR + "}")
+       @Secured({ DashboardConstants.ROLE_ADMIN })
        public void modifyNcrt(@PathVariable(PP_SERVING) String servingCellNrcgi, //
                        @PathVariable(PP_NEIGHBOR) String neighborCellNrpci, //
                        @RequestBody NeighborCellRelationMod ncrMod, HttpServletResponse response) {
@@ -145,6 +153,7 @@ public class AnrXappController {
 
        @ApiOperation(value = "Delete neighbor cell relation based on Serving Cell NRCGI and Neighbor Cell NRPCI")
        @DeleteMapping(NCRT_METHOD + "/" + PP_SERVING + "/{" + PP_SERVING + "}/" + PP_NEIGHBOR + "/{" + PP_NEIGHBOR + "}")
+       @Secured({ DashboardConstants.ROLE_ADMIN })
        public void deleteNcrt(@PathVariable(PP_SERVING) String servingCellNrcgi, //
                        @PathVariable(PP_NEIGHBOR) String neighborCellNrpci, //
                        HttpServletResponse response) {