Fix formatting in the dashboard
[nonrtric.git] / dashboard / webapp-backend / src / main / java / org / oransc / ric / portal / dashboard / controller / PolicyController.java
index 529cd2a..5b90931 100644 (file)
  */
 package org.oransc.ric.portal.dashboard.controller;
 
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+
+import io.swagger.annotations.ApiOperation;
+
 import java.lang.invoke.MethodHandles;
+import java.util.Collection;
 
 import javax.servlet.http.HttpServletResponse;
 
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-
-import org.oransc.ric.portal.dashboard.DashboardApplication;
 import org.oransc.ric.portal.dashboard.DashboardConstants;
 import org.oransc.ric.portal.dashboard.exceptions.HttpBadRequestException;
 import org.oransc.ric.portal.dashboard.exceptions.HttpInternalServerErrorException;
@@ -34,7 +36,6 @@ import org.oransc.ric.portal.dashboard.exceptions.HttpNotFoundException;
 import org.oransc.ric.portal.dashboard.exceptions.HttpNotImplementedException;
 import org.oransc.ric.portal.dashboard.model.PolicyInstances;
 import org.oransc.ric.portal.dashboard.model.PolicyTypes;
-import org.oransc.ric.portal.dashboard.model.SuccessTransport;
 import org.oransc.ric.portal.dashboard.policyagentapi.PolicyAgentApi;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -52,8 +53,6 @@ import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
-import java.util.Collection;
-import io.swagger.annotations.ApiOperation;
 
 /**
  * Proxies calls from the front end to the Policy agent API.
@@ -67,117 +66,117 @@ import io.swagger.annotations.ApiOperation;
 @RequestMapping(value = PolicyController.CONTROLLER_PATH, produces = MediaType.APPLICATION_JSON_VALUE)
 public class PolicyController {
 
-       private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
-       private static Gson gson = new GsonBuilder() //
-                       .serializeNulls() //
-                       .create(); //
-
-       // Publish paths in constants so tests are easy to write
-       public static final String CONTROLLER_PATH = DashboardConstants.ENDPOINT_PREFIX + "/policy";
-       // Endpoints
-       public static final String VERSION_METHOD = DashboardConstants.VERSION_METHOD;
-       public static final String POLICY_TYPES_METHOD = "policytypes";
-       public static final String POLICY_TYPE_ID_NAME = "policy_type_id";
-       public static final String POLICIES_NAME = "policies";
-       public static final String POLICY_INSTANCE_ID_NAME = "policy_instance_id";
-
-       // Populated by the autowired constructor
-       private final PolicyAgentApi policyAgentApi;
-
-       @Autowired
-       public PolicyController(final PolicyAgentApi policyAgentApi) {
-               Assert.notNull(policyAgentApi, "API must not be null");
-               this.policyAgentApi = policyAgentApi;
-               logger.debug("ctor: configured with client type {}", policyAgentApi.getClass().getName());
-       }
-
-       /*
-        * The fields are defined in the Policy Control Typescript interface.
-        */
-       @ApiOperation(value = "Gets the policy types from Near Realtime-RIC")
-       @GetMapping(POLICY_TYPES_METHOD)
-       @Secured({ DashboardConstants.ROLE_ADMIN, DashboardConstants.ROLE_STANDARD })
-       public ResponseEntity<PolicyTypes> getAllPolicyTypes(HttpServletResponse response) {
-               logger.debug("getAllPolicyTypes");
-               return this.policyAgentApi.getAllPolicyTypes();
-       }
-
-       @ApiOperation(value = "Returns the policy instances for the given policy type.")
-       @GetMapping(POLICY_TYPES_METHOD + "/{" + POLICY_TYPE_ID_NAME + "}/" + POLICIES_NAME)
-       @Secured({ DashboardConstants.ROLE_ADMIN, DashboardConstants.ROLE_STANDARD })
-       public ResponseEntity<String> getPolicyInstances(@PathVariable(POLICY_TYPE_ID_NAME) String policyTypeIdString) {
-               logger.debug("getPolicyInstances {}", policyTypeIdString);
-
-               ResponseEntity<PolicyInstances> response = this.policyAgentApi.getPolicyInstancesForType(policyTypeIdString);
-               if (!response.getStatusCode().is2xxSuccessful()) {
-                       return new ResponseEntity<>(response.getStatusCode());
-               }
-               String json = gson.toJson(response.getBody());
-               return new ResponseEntity<>(json, response.getStatusCode());
-       }
-
-       @ApiOperation(value = "Returns a policy instance of a type")
-       @GetMapping(POLICY_TYPES_METHOD + "/{" + POLICY_TYPE_ID_NAME + "}/" + POLICIES_NAME + "/{" + POLICY_INSTANCE_ID_NAME
-                       + "}")
-       @Secured({ DashboardConstants.ROLE_ADMIN, DashboardConstants.ROLE_STANDARD })
-       public ResponseEntity<String> getPolicyInstance(@PathVariable(POLICY_TYPE_ID_NAME) String policyTypeIdString,
-                       @PathVariable(POLICY_INSTANCE_ID_NAME) String policyInstanceId) {
-               logger.debug("getPolicyInstance {}:{}", policyTypeIdString, policyInstanceId);
-               return this.policyAgentApi.getPolicyInstance(policyInstanceId);
-       }
-
-       @ApiOperation(value = "Creates the policy instances for the given policy type.")
-       @PutMapping(POLICY_TYPES_METHOD + "/{" + POLICY_TYPE_ID_NAME + "}/" + POLICIES_NAME + "/{" + POLICY_INSTANCE_ID_NAME
-                       + "}")
-       @Secured({ DashboardConstants.ROLE_ADMIN })
-       public ResponseEntity<String> putPolicyInstance(@PathVariable(POLICY_TYPE_ID_NAME) String policyTypeIdString,
-                       @RequestParam(name = "ric", required = true) String ric,
-                       @PathVariable(POLICY_INSTANCE_ID_NAME) String policyInstanceId, @RequestBody String instance) {
-               logger.debug("putPolicyInstance typeId: {}, instanceId: {}, instance: {}", policyTypeIdString, policyInstanceId,
-                               instance);
-               return this.policyAgentApi.putPolicy(policyTypeIdString, policyInstanceId, instance, ric);
-       }
-
-       @ApiOperation(value = "Deletes the policy instances for the given policy type.")
-       @DeleteMapping(POLICY_TYPES_METHOD + "/{" + POLICY_TYPE_ID_NAME + "}/" + POLICIES_NAME + "/{"
-                       + POLICY_INSTANCE_ID_NAME + "}")
-       @Secured({ DashboardConstants.ROLE_ADMIN })
-       public void deletePolicyInstance(@PathVariable(POLICY_TYPE_ID_NAME) String policyTypeIdString,
-                       @PathVariable(POLICY_INSTANCE_ID_NAME) String policyInstanceId) {
-               logger.debug("deletePolicyInstance typeId: {}, instanceId: {}", policyTypeIdString, policyInstanceId);
-               this.policyAgentApi.deletePolicy(policyInstanceId);
-       }
-
-       private void checkHttpError(String httpCode) {
-               logger.debug("Http Response Code: {}", httpCode);
-               if (httpCode.equals(String.valueOf(HttpStatus.NOT_FOUND.value()))) {
-                       logger.error("Caught HttpNotFoundException");
-                       throw new HttpNotFoundException("Not Found Exception");
-               } else if (httpCode.equals(String.valueOf(HttpStatus.BAD_REQUEST.value()))) {
-                       logger.error("Caught HttpBadRequestException");
-                       throw new HttpBadRequestException("Bad Request Exception");
-               } else if (httpCode.equals(String.valueOf(HttpStatus.INTERNAL_SERVER_ERROR.value()))) {
-                       logger.error("Caught HttpInternalServerErrorException");
-                       throw new HttpInternalServerErrorException("Internal Server Error Exception");
-               } else if (httpCode.equals(String.valueOf(HttpStatus.NOT_IMPLEMENTED.value()))) {
-                       logger.error("Caught HttpNotImplementedException");
-                       throw new HttpNotImplementedException("Not Implemented Exception");
-               }
-       }
-
-       @ApiOperation(value = "Returns the rics supporting the given policy type.")
-       @GetMapping("/rics")
-       @Secured({ DashboardConstants.ROLE_ADMIN, DashboardConstants.ROLE_STANDARD })
-       public ResponseEntity<String> getRicsSupportingType(
-                       @RequestParam(name = "policyType", required = true) String supportingPolicyType) {
-               logger.debug("getRicsSupportingType {}", supportingPolicyType);
-
-               ResponseEntity<Collection<String>> result = this.policyAgentApi.getRicsSupportingType(supportingPolicyType);
-               if (!result.getStatusCode().is2xxSuccessful()) {
-                       return new ResponseEntity<>(result.getStatusCode());
-               }
-               String json = gson.toJson(result.getBody());
-               return new ResponseEntity<>(json, result.getStatusCode());
-       }
+    private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+    private static Gson gson = new GsonBuilder() //
+        .serializeNulls() //
+        .create(); //
+
+    // Publish paths in constants so tests are easy to write
+    public static final String CONTROLLER_PATH = DashboardConstants.ENDPOINT_PREFIX + "/policy";
+    // Endpoints
+    public static final String VERSION_METHOD = DashboardConstants.VERSION_METHOD;
+    public static final String POLICY_TYPES_METHOD = "policytypes";
+    public static final String POLICY_TYPE_ID_NAME = "policy_type_id";
+    public static final String POLICIES_NAME = "policies";
+    public static final String POLICY_INSTANCE_ID_NAME = "policy_instance_id";
+
+    // Populated by the autowired constructor
+    private final PolicyAgentApi policyAgentApi;
+
+    @Autowired
+    public PolicyController(final PolicyAgentApi policyAgentApi) {
+        Assert.notNull(policyAgentApi, "API must not be null");
+        this.policyAgentApi = policyAgentApi;
+        logger.debug("ctor: configured with client type {}", policyAgentApi.getClass().getName());
+    }
+
+    /*
+     * The fields are defined in the Policy Control Typescript interface.
+     */
+    @ApiOperation(value = "Gets the policy types from Near Realtime-RIC")
+    @GetMapping(POLICY_TYPES_METHOD)
+    @Secured({DashboardConstants.ROLE_ADMIN, DashboardConstants.ROLE_STANDARD})
+    public ResponseEntity<PolicyTypes> getAllPolicyTypes(HttpServletResponse response) {
+        logger.debug("getAllPolicyTypes");
+        return this.policyAgentApi.getAllPolicyTypes();
+    }
+
+    @ApiOperation(value = "Returns the policy instances for the given policy type.")
+    @GetMapping(POLICY_TYPES_METHOD + "/{" + POLICY_TYPE_ID_NAME + "}/" + POLICIES_NAME)
+    @Secured({DashboardConstants.ROLE_ADMIN, DashboardConstants.ROLE_STANDARD})
+    public ResponseEntity<String> getPolicyInstances(@PathVariable(POLICY_TYPE_ID_NAME) String policyTypeIdString) {
+        logger.debug("getPolicyInstances {}", policyTypeIdString);
+
+        ResponseEntity<PolicyInstances> response = this.policyAgentApi.getPolicyInstancesForType(policyTypeIdString);
+        if (!response.getStatusCode().is2xxSuccessful()) {
+            return new ResponseEntity<>(response.getStatusCode());
+        }
+        String json = gson.toJson(response.getBody());
+        return new ResponseEntity<>(json, response.getStatusCode());
+    }
+
+    @ApiOperation(value = "Returns a policy instance of a type")
+    @GetMapping(POLICY_TYPES_METHOD + "/{" + POLICY_TYPE_ID_NAME + "}/" + POLICIES_NAME + "/{" + POLICY_INSTANCE_ID_NAME
+        + "}")
+    @Secured({DashboardConstants.ROLE_ADMIN, DashboardConstants.ROLE_STANDARD})
+    public ResponseEntity<String> getPolicyInstance(@PathVariable(POLICY_TYPE_ID_NAME) String policyTypeIdString,
+        @PathVariable(POLICY_INSTANCE_ID_NAME) String policyInstanceId) {
+        logger.debug("getPolicyInstance {}:{}", policyTypeIdString, policyInstanceId);
+        return this.policyAgentApi.getPolicyInstance(policyInstanceId);
+    }
+
+    @ApiOperation(value = "Creates the policy instances for the given policy type.")
+    @PutMapping(POLICY_TYPES_METHOD + "/{" + POLICY_TYPE_ID_NAME + "}/" + POLICIES_NAME + "/{" + POLICY_INSTANCE_ID_NAME
+        + "}")
+    @Secured({DashboardConstants.ROLE_ADMIN})
+    public ResponseEntity<String> putPolicyInstance(@PathVariable(POLICY_TYPE_ID_NAME) String policyTypeIdString,
+        @RequestParam(name = "ric", required = true) String ric,
+        @PathVariable(POLICY_INSTANCE_ID_NAME) String policyInstanceId, @RequestBody String instance) {
+        logger.debug("putPolicyInstance typeId: {}, instanceId: {}, instance: {}", policyTypeIdString, policyInstanceId,
+            instance);
+        return this.policyAgentApi.putPolicy(policyTypeIdString, policyInstanceId, instance, ric);
+    }
+
+    @ApiOperation(value = "Deletes the policy instances for the given policy type.")
+    @DeleteMapping(POLICY_TYPES_METHOD + "/{" + POLICY_TYPE_ID_NAME + "}/" + POLICIES_NAME + "/{"
+        + POLICY_INSTANCE_ID_NAME + "}")
+    @Secured({DashboardConstants.ROLE_ADMIN})
+    public void deletePolicyInstance(@PathVariable(POLICY_TYPE_ID_NAME) String policyTypeIdString,
+        @PathVariable(POLICY_INSTANCE_ID_NAME) String policyInstanceId) {
+        logger.debug("deletePolicyInstance typeId: {}, instanceId: {}", policyTypeIdString, policyInstanceId);
+        this.policyAgentApi.deletePolicy(policyInstanceId);
+    }
+
+    private void checkHttpError(String httpCode) {
+        logger.debug("Http Response Code: {}", httpCode);
+        if (httpCode.equals(String.valueOf(HttpStatus.NOT_FOUND.value()))) {
+            logger.error("Caught HttpNotFoundException");
+            throw new HttpNotFoundException("Not Found Exception");
+        } else if (httpCode.equals(String.valueOf(HttpStatus.BAD_REQUEST.value()))) {
+            logger.error("Caught HttpBadRequestException");
+            throw new HttpBadRequestException("Bad Request Exception");
+        } else if (httpCode.equals(String.valueOf(HttpStatus.INTERNAL_SERVER_ERROR.value()))) {
+            logger.error("Caught HttpInternalServerErrorException");
+            throw new HttpInternalServerErrorException("Internal Server Error Exception");
+        } else if (httpCode.equals(String.valueOf(HttpStatus.NOT_IMPLEMENTED.value()))) {
+            logger.error("Caught HttpNotImplementedException");
+            throw new HttpNotImplementedException("Not Implemented Exception");
+        }
+    }
+
+    @ApiOperation(value = "Returns the rics supporting the given policy type.")
+    @GetMapping("/rics")
+    @Secured({DashboardConstants.ROLE_ADMIN, DashboardConstants.ROLE_STANDARD})
+    public ResponseEntity<String> getRicsSupportingType(
+        @RequestParam(name = "policyType", required = true) String supportingPolicyType) {
+        logger.debug("getRicsSupportingType {}", supportingPolicyType);
+
+        ResponseEntity<Collection<String>> result = this.policyAgentApi.getRicsSupportingType(supportingPolicyType);
+        if (!result.getStatusCode().is2xxSuccessful()) {
+            return new ResponseEntity<>(result.getStatusCode());
+        }
+        String json = gson.toJson(result.getBody());
+        return new ResponseEntity<>(json, result.getStatusCode());
+    }
 
 };