X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=dashboard%2Fwebapp-backend%2Fsrc%2Fmain%2Fjava%2Forg%2Foransc%2Fric%2Fportal%2Fdashboard%2Fcontroller%2FPolicyController.java;h=20a0c3f57329143020dd12fd1a4f887783325ffb;hb=d5aaf1cc8be867a6b298f1e79069f7445ddbfb57;hp=5b90931435f183d101d6e0812430085e3681450b;hpb=592ce20ec359928373de2e7f06214c8f8ad73c20;p=nonrtric.git diff --git a/dashboard/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/controller/PolicyController.java b/dashboard/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/controller/PolicyController.java index 5b909314..20a0c3f5 100644 --- a/dashboard/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/controller/PolicyController.java +++ b/dashboard/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/controller/PolicyController.java @@ -19,28 +19,17 @@ */ 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 org.oransc.ric.portal.dashboard.DashboardConstants; -import org.oransc.ric.portal.dashboard.exceptions.HttpBadRequestException; -import org.oransc.ric.portal.dashboard.exceptions.HttpInternalServerErrorException; -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.policyagentapi.PolicyAgentApi; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.security.access.annotation.Secured; @@ -67,9 +56,6 @@ import org.springframework.web.bind.annotation.RestController; 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"; @@ -95,88 +81,59 @@ public class PolicyController { */ @ApiOperation(value = "Gets the policy types from Near Realtime-RIC") @GetMapping(POLICY_TYPES_METHOD) - @Secured({DashboardConstants.ROLE_ADMIN, DashboardConstants.ROLE_STANDARD}) - public ResponseEntity getAllPolicyTypes(HttpServletResponse response) { + @Secured({ DashboardConstants.ROLE_ADMIN, DashboardConstants.ROLE_STANDARD }) + public ResponseEntity 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}) + @Secured({ DashboardConstants.ROLE_ADMIN, DashboardConstants.ROLE_STANDARD }) public ResponseEntity getPolicyInstances(@PathVariable(POLICY_TYPE_ID_NAME) String policyTypeIdString) { logger.debug("getPolicyInstances {}", policyTypeIdString); - - ResponseEntity 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()); + return this.policyAgentApi.getPolicyInstancesForType(policyTypeIdString); } @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 getPolicyInstance(@PathVariable(POLICY_TYPE_ID_NAME) String policyTypeIdString, - @PathVariable(POLICY_INSTANCE_ID_NAME) String policyInstanceId) { + + "}") + @Secured({ DashboardConstants.ROLE_ADMIN, DashboardConstants.ROLE_STANDARD }) + public ResponseEntity 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}) + + "}") + @Secured({ DashboardConstants.ROLE_ADMIN }) public ResponseEntity 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) { + @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); + 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) { + + POLICY_INSTANCE_ID_NAME + "}") + @Secured({ DashboardConstants.ROLE_ADMIN }) + public ResponseEntity 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"); - } + return this.policyAgentApi.deletePolicy(policyInstanceId); } @ApiOperation(value = "Returns the rics supporting the given policy type.") @GetMapping("/rics") - @Secured({DashboardConstants.ROLE_ADMIN, DashboardConstants.ROLE_STANDARD}) + @Secured({ DashboardConstants.ROLE_ADMIN, DashboardConstants.ROLE_STANDARD }) public ResponseEntity getRicsSupportingType( - @RequestParam(name = "policyType", required = true) String supportingPolicyType) { + @RequestParam(name = "policyType", required = true) String supportingPolicyType) { logger.debug("getRicsSupportingType {}", supportingPolicyType); - ResponseEntity> 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()); + return this.policyAgentApi.getRicsSupportingType(supportingPolicyType); } - -}; +}