X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=main%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fapi%2Fmain%2Frest%2FApiRestController.java;h=7661c27341876559722b509f04e22790264c7a05;hb=868e611e573e8ce8cbc1d2549752232088ed1cff;hp=60ccba0f87926ed84e3b4ff7b0b5e93dc53545d1;hpb=669280a0305dc1c2be1c278b4e80f70429fc0bdf;p=policy%2Fapi.git diff --git a/main/src/main/java/org/onap/policy/api/main/rest/ApiRestController.java b/main/src/main/java/org/onap/policy/api/main/rest/ApiRestController.java index 60ccba0f..7661c273 100644 --- a/main/src/main/java/org/onap/policy/api/main/rest/ApiRestController.java +++ b/main/src/main/java/org/onap/policy/api/main/rest/ApiRestController.java @@ -4,6 +4,7 @@ * ================================================================================ * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved. * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,16 +37,21 @@ import io.swagger.annotations.Info; import io.swagger.annotations.ResponseHeader; import io.swagger.annotations.SecurityDefinition; import io.swagger.annotations.SwaggerDefinition; + import java.util.UUID; + import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; +import javax.ws.rs.DefaultValue; import javax.ws.rs.GET; import javax.ws.rs.HeaderParam; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; import javax.ws.rs.core.Response; + import org.onap.policy.api.main.rest.provider.HealthCheckProvider; import org.onap.policy.api.main.rest.provider.PolicyProvider; import org.onap.policy.api.main.rest.provider.PolicyTypeProvider; @@ -69,19 +75,20 @@ import org.slf4j.LoggerFactory; @Api(value = "Policy Design API") @Produces({"application/json", "application/yaml"}) @Consumes({"application/json", "application/yaml"}) -@SwaggerDefinition(info = @Info( +@SwaggerDefinition( + info = @Info( description = "Policy Design API is publicly exposed for clients to Create/Read/Update/Delete" - + " policy types, policy type implementation and policies which can be recognized" - + " and executable by incorporated policy engines. It is an" - + " independent component running rest service that takes all policy design API calls" - + " from clients and then assign them to different API working functions. Besides" - + " that, API is also exposed for clients to retrieve healthcheck status of this API" - + " rest service and the statistics report including the counters of API invocation.", + + " policy types, policy type implementation and policies which can be recognized" + + " and executable by incorporated policy engines. It is an" + + " independent component running rest service that takes all policy design API calls" + + " from clients and then assign them to different API working functions. Besides" + + " that, API is also exposed for clients to retrieve healthcheck status of this API" + + " rest service and the statistics report including the counters of API invocation.", version = "1.0.0", title = "Policy Design", extensions = {@Extension(properties = {@ExtensionProperty(name = "planned-retirement-date", value = "tbd"), @ExtensionProperty(name = "component", value = "Policy Framework")})}), - schemes = {SwaggerDefinition.Scheme.HTTP, SwaggerDefinition.Scheme.HTTPS}, - securityDefinition = @SecurityDefinition(basicAuthDefinitions = {@BasicAuthDefinition(key = "basicAuth")})) + schemes = {SwaggerDefinition.Scheme.HTTP, SwaggerDefinition.Scheme.HTTPS}, + securityDefinition = @SecurityDefinition(basicAuthDefinitions = {@BasicAuthDefinition(key = "basicAuth")})) public class ApiRestController extends CommonRestController { private static final Logger LOGGER = LoggerFactory.getLogger(ApiRestController.class); @@ -94,30 +101,29 @@ public class ApiRestController extends CommonRestController { @GET @Path("/healthcheck") @ApiOperation(value = "Perform a system healthcheck", notes = "Returns healthy status of the Policy API component", - response = HealthCheckReport.class, - responseHeaders = { - @ResponseHeader(name = "X-MinorVersion", - description = "Used to request or communicate a MINOR version back from the client" - + " to the server, and from the server back to the client", - response = String.class), - @ResponseHeader(name = "X-PatchVersion", - description = "Used only to communicate a PATCH version in a response for" - + " troubleshooting purposes only, and will not be provided by" - + " the client on request", - response = String.class), - @ResponseHeader(name = "X-LatestVersion", - description = "Used only to communicate an API's latest version", response = String.class), - @ResponseHeader(name = "X-ONAP-RequestID", - description = "Used to track REST transactions for logging purpose", response = UUID.class)}, - authorizations = @Authorization(value = "basicAuth"), tags = {"HealthCheck",}, - extensions = {@Extension(name = "interface info", - properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"), - @ExtensionProperty(name = "last-mod-release", value = "Dublin")})}) + response = HealthCheckReport.class, + responseHeaders = { + @ResponseHeader(name = "X-MinorVersion", + description = "Used to request or communicate a MINOR version back from the client" + + " to the server, and from the server back to the client", + response = String.class), + @ResponseHeader(name = "X-PatchVersion", + description = "Used only to communicate a PATCH version in a response for" + + " troubleshooting purposes only, and will not be provided by" + " the client on request", + response = String.class), + @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version", + response = String.class), + @ResponseHeader(name = "X-ONAP-RequestID", + description = "Used to track REST transactions for logging purpose", response = UUID.class)}, + authorizations = @Authorization(value = "basicAuth"), tags = {"HealthCheck",}, + extensions = { + @Extension(name = "interface info", properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"), + @ExtensionProperty(name = "last-mod-release", value = "Dublin")})}) @ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"), @ApiResponse(code = 403, message = "Authorization Error"), @ApiResponse(code = 500, message = "Internal Server Error")}) - public Response getHealthCheck( - @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) { + public Response + getHealthCheck(@HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) { updateApiStatisticsCounter(Target.OTHER, Result.SUCCESS, HttpMethod.GET); return makeOkResponse(requestId, new HealthCheckProvider().performHealthCheck()); @@ -131,31 +137,30 @@ public class ApiRestController extends CommonRestController { @GET @Path("/statistics") @ApiOperation(value = "Retrieve current statistics", - notes = "Returns current statistics including the counters of API invocation", - response = StatisticsReport.class, - responseHeaders = { - @ResponseHeader(name = "X-MinorVersion", - description = "Used to request or communicate a MINOR version back from the client" - + " to the server, and from the server back to the client", - response = String.class), - @ResponseHeader(name = "X-PatchVersion", - description = "Used only to communicate a PATCH version in a response for" - + " troubleshooting purposes only, and will not be provided by" - + " the client on request", - response = String.class), - @ResponseHeader(name = "X-LatestVersion", - description = "Used only to communicate an API's latest version", response = String.class), - @ResponseHeader(name = "X-ONAP-RequestID", - description = "Used to track REST transactions for logging purpose", response = UUID.class)}, - authorizations = @Authorization(value = "basicAuth"), tags = {"Statistics",}, - extensions = {@Extension(name = "interface info", - properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"), - @ExtensionProperty(name = "last-mod-release", value = "Dublin")})}) + notes = "Returns current statistics including the counters of API invocation", + response = StatisticsReport.class, + responseHeaders = { + @ResponseHeader(name = "X-MinorVersion", + description = "Used to request or communicate a MINOR version back from the client" + + " to the server, and from the server back to the client", + response = String.class), + @ResponseHeader(name = "X-PatchVersion", + description = "Used only to communicate a PATCH version in a response for" + + " troubleshooting purposes only, and will not be provided by" + " the client on request", + response = String.class), + @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version", + response = String.class), + @ResponseHeader(name = "X-ONAP-RequestID", + description = "Used to track REST transactions for logging purpose", response = UUID.class)}, + authorizations = @Authorization(value = "basicAuth"), tags = {"Statistics",}, + extensions = { + @Extension(name = "interface info", properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"), + @ExtensionProperty(name = "last-mod-release", value = "Dublin")})}) @ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"), @ApiResponse(code = 403, message = "Authorization Error"), @ApiResponse(code = 500, message = "Internal Server Error")}) public Response - getStatistics(@HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) { + getStatistics(@HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) { updateApiStatisticsCounter(Target.OTHER, Result.SUCCESS, HttpMethod.GET); @@ -170,31 +175,30 @@ public class ApiRestController extends CommonRestController { @GET @Path("/policytypes") @ApiOperation(value = "Retrieve existing policy types", - notes = "Returns a list of existing policy types stored in Policy Framework", - response = ToscaServiceTemplate.class, - responseHeaders = { - @ResponseHeader(name = "X-MinorVersion", - description = "Used to request or communicate a MINOR version back from the client" - + " to the server, and from the server back to the client", - response = String.class), - @ResponseHeader(name = "X-PatchVersion", - description = "Used only to communicate a PATCH version in a response for" - + " troubleshooting purposes only, and will not be provided by" - + " the client on request", - response = String.class), - @ResponseHeader(name = "X-LatestVersion", - description = "Used only to communicate an API's latest version", response = String.class), - @ResponseHeader(name = "X-ONAP-RequestID", - description = "Used to track REST transactions for logging purpose", response = UUID.class)}, - authorizations = @Authorization(value = "basicAuth"), tags = {"PolicyType",}, - extensions = {@Extension(name = "interface info", - properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"), - @ExtensionProperty(name = "last-mod-release", value = "Dublin")})}) + notes = "Returns a list of existing policy types stored in Policy Framework", + response = ToscaServiceTemplate.class, + responseHeaders = { + @ResponseHeader(name = "X-MinorVersion", + description = "Used to request or communicate a MINOR version back from the client" + + " to the server, and from the server back to the client", + response = String.class), + @ResponseHeader(name = "X-PatchVersion", + description = "Used only to communicate a PATCH version in a response for" + + " troubleshooting purposes only, and will not be provided by" + " the client on request", + response = String.class), + @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version", + response = String.class), + @ResponseHeader(name = "X-ONAP-RequestID", + description = "Used to track REST transactions for logging purpose", response = UUID.class)}, + authorizations = @Authorization(value = "basicAuth"), tags = {"PolicyType",}, + extensions = { + @Extension(name = "interface info", properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"), + @ExtensionProperty(name = "last-mod-release", value = "Dublin")})}) @ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"), @ApiResponse(code = 403, message = "Authorization Error"), @ApiResponse(code = 500, message = "Internal Server Error")}) - public Response getAllPolicyTypes( - @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) { + public Response + getAllPolicyTypes(@HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) { try (PolicyTypeProvider policyTypeProvider = new PolicyTypeProvider()) { ToscaServiceTemplate serviceTemplate = policyTypeProvider.fetchPolicyTypes(null, null); @@ -217,33 +221,32 @@ public class ApiRestController extends CommonRestController { @GET @Path("/policytypes/{policyTypeId}") @ApiOperation(value = "Retrieve all available versions of a policy type", - notes = "Returns a list of all available versions for the specified policy type", - response = ToscaServiceTemplate.class, - responseHeaders = { - @ResponseHeader(name = "X-MinorVersion", - description = "Used to request or communicate a MINOR version back from the client" - + " to the server, and from the server back to the client", - response = String.class), - @ResponseHeader(name = "X-PatchVersion", - description = "Used only to communicate a PATCH version in a response for" - + " troubleshooting purposes only, and will not be provided by" - + " the client on request", - response = String.class), - @ResponseHeader(name = "X-LatestVersion", - description = "Used only to communicate an API's latest version", response = String.class), - @ResponseHeader(name = "X-ONAP-RequestID", - description = "Used to track REST transactions for logging purpose", response = UUID.class)}, - authorizations = @Authorization(value = "basicAuth"), tags = {"PolicyType",}, - extensions = {@Extension(name = "interface info", - properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"), - @ExtensionProperty(name = "last-mod-release", value = "Dublin")})}) + notes = "Returns a list of all available versions for the specified policy type", + response = ToscaServiceTemplate.class, + responseHeaders = { + @ResponseHeader(name = "X-MinorVersion", + description = "Used to request or communicate a MINOR version back from the client" + + " to the server, and from the server back to the client", + response = String.class), + @ResponseHeader(name = "X-PatchVersion", + description = "Used only to communicate a PATCH version in a response for" + + " troubleshooting purposes only, and will not be provided by" + " the client on request", + response = String.class), + @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version", + response = String.class), + @ResponseHeader(name = "X-ONAP-RequestID", + description = "Used to track REST transactions for logging purpose", response = UUID.class)}, + authorizations = @Authorization(value = "basicAuth"), tags = {"PolicyType",}, + extensions = { + @Extension(name = "interface info", properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"), + @ExtensionProperty(name = "last-mod-release", value = "Dublin")})}) @ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"), @ApiResponse(code = 403, message = "Authorization Error"), @ApiResponse(code = 404, message = "Resource Not Found"), @ApiResponse(code = 500, message = "Internal Server Error")}) public Response getAllVersionsOfPolicyType( - @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId, - @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) { + @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId, + @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) { try (PolicyTypeProvider policyTypeProvider = new PolicyTypeProvider()) { ToscaServiceTemplate serviceTemplate = policyTypeProvider.fetchPolicyTypes(policyTypeId, null); @@ -267,33 +270,32 @@ public class ApiRestController extends CommonRestController { @GET @Path("/policytypes/{policyTypeId}/versions/{versionId}") @ApiOperation(value = "Retrieve one particular version of a policy type", - notes = "Returns a particular version for the specified policy type", response = ToscaServiceTemplate.class, - responseHeaders = { - @ResponseHeader(name = "X-MinorVersion", - description = "Used to request or communicate a MINOR version back from the client" - + " to the server, and from the server back to the client", - response = String.class), - @ResponseHeader(name = "X-PatchVersion", - description = "Used only to communicate a PATCH version in a response for" - + " troubleshooting purposes only, and will not be provided by" - + " the client on request", - response = String.class), - @ResponseHeader(name = "X-LatestVersion", - description = "Used only to communicate an API's latest version", response = String.class), - @ResponseHeader(name = "X-ONAP-RequestID", - description = "Used to track REST transactions for logging purpose", response = UUID.class)}, - authorizations = @Authorization(value = "basicAuth"), tags = {"PolicyType",}, - extensions = {@Extension(name = "interface info", - properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"), - @ExtensionProperty(name = "last-mod-release", value = "Dublin")})}) + notes = "Returns a particular version for the specified policy type", response = ToscaServiceTemplate.class, + responseHeaders = { + @ResponseHeader(name = "X-MinorVersion", + description = "Used to request or communicate a MINOR version back from the client" + + " to the server, and from the server back to the client", + response = String.class), + @ResponseHeader(name = "X-PatchVersion", + description = "Used only to communicate a PATCH version in a response for" + + " troubleshooting purposes only, and will not be provided by" + " the client on request", + response = String.class), + @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version", + response = String.class), + @ResponseHeader(name = "X-ONAP-RequestID", + description = "Used to track REST transactions for logging purpose", response = UUID.class)}, + authorizations = @Authorization(value = "basicAuth"), tags = {"PolicyType",}, + extensions = { + @Extension(name = "interface info", properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"), + @ExtensionProperty(name = "last-mod-release", value = "Dublin")})}) @ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"), @ApiResponse(code = 403, message = "Authorization Error"), @ApiResponse(code = 404, message = "Resource Not Found"), @ApiResponse(code = 500, message = "Internal Server Error")}) public Response getSpecificVersionOfPolicyType( - @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId, - @PathParam("versionId") @ApiParam(value = "Version of policy type", required = true) String versionId, - @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) { + @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId, + @PathParam("versionId") @ApiParam(value = "Version of policy type", required = true) String versionId, + @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) { try (PolicyTypeProvider policyTypeProvider = new PolicyTypeProvider()) { ToscaServiceTemplate serviceTemplate = policyTypeProvider.fetchPolicyTypes(policyTypeId, versionId); @@ -316,32 +318,31 @@ public class ApiRestController extends CommonRestController { @GET @Path("/policytypes/{policyTypeId}/versions/latest") @ApiOperation(value = "Retrieve latest version of a policy type", - notes = "Returns latest version for the specified policy type", response = ToscaServiceTemplate.class, - responseHeaders = { - @ResponseHeader(name = "X-MinorVersion", - description = "Used to request or communicate a MINOR version back from the client" - + " to the server, and from the server back to the client", - response = String.class), - @ResponseHeader(name = "X-PatchVersion", - description = "Used only to communicate a PATCH version in a response for" - + " troubleshooting purposes only, and will not be provided by" - + " the client on request", - response = String.class), - @ResponseHeader(name = "X-LatestVersion", - description = "Used only to communicate an API's latest version", response = String.class), - @ResponseHeader(name = "X-ONAP-RequestID", - description = "Used to track REST transactions for logging purpose", response = UUID.class)}, - authorizations = @Authorization(value = "basicAuth"), tags = {"PolicyType",}, - extensions = {@Extension(name = "interface info", - properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"), - @ExtensionProperty(name = "last-mod-release", value = "Dublin")})}) + notes = "Returns latest version for the specified policy type", response = ToscaServiceTemplate.class, + responseHeaders = { + @ResponseHeader(name = "X-MinorVersion", + description = "Used to request or communicate a MINOR version back from the client" + + " to the server, and from the server back to the client", + response = String.class), + @ResponseHeader(name = "X-PatchVersion", + description = "Used only to communicate a PATCH version in a response for" + + " troubleshooting purposes only, and will not be provided by" + " the client on request", + response = String.class), + @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version", + response = String.class), + @ResponseHeader(name = "X-ONAP-RequestID", + description = "Used to track REST transactions for logging purpose", response = UUID.class)}, + authorizations = @Authorization(value = "basicAuth"), tags = {"PolicyType",}, + extensions = { + @Extension(name = "interface info", properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"), + @ExtensionProperty(name = "last-mod-release", value = "Dublin")})}) @ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"), @ApiResponse(code = 403, message = "Authorization Error"), @ApiResponse(code = 404, message = "Resource Not Found"), @ApiResponse(code = 500, message = "Internal Server Error")}) public Response getLatestVersionOfPolicyType( - @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId, - @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) { + @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId, + @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) { try (PolicyTypeProvider policyTypeProvider = new PolicyTypeProvider()) { ToscaServiceTemplate serviceTemplate = policyTypeProvider.fetchLatestPolicyTypes(policyTypeId); @@ -364,41 +365,32 @@ public class ApiRestController extends CommonRestController { @POST @Path("/policytypes") @ApiOperation(value = "Create a new policy type", notes = "Client should provide TOSCA body of the new policy type", - authorizations = @Authorization(value = "basicAuth"), tags = {"PolicyType",}, - response = ToscaServiceTemplate.class, - responseHeaders = { - @ResponseHeader(name = "X-MinorVersion", - description = "Used to request or communicate a MINOR version back from the client" - + " to the server, and from the server back to the client", - response = String.class), - @ResponseHeader(name = "X-PatchVersion", - description = "Used only to communicate a PATCH version in a response for" - + " troubleshooting purposes only, and will not be provided by" - + " the client on request", - response = String.class), - @ResponseHeader(name = "X-LatestVersion", - description = "Used only to communicate an API's latest version", - response = String.class), - @ResponseHeader(name = "X-ONAP-RequestID", - description = "Used to track REST transactions for logging purpose", - response = UUID.class) - }, - extensions = { - @Extension(name = "interface info", properties = { - @ExtensionProperty(name = "api-version", value = "1.0.0"), - @ExtensionProperty(name = "last-mod-release", value = "Dublin") - }) - }) - @ApiResponses(value = { - @ApiResponse(code = 400, message = "Invalid Body"), - @ApiResponse(code = 401, message = "Authentication Error"), - @ApiResponse(code = 403, message = "Authorization Error"), - @ApiResponse(code = 406, message = "Not Acceptable Payload"), - @ApiResponse(code = 500, message = "Internal Server Error") - }) + authorizations = @Authorization(value = "basicAuth"), tags = {"PolicyType",}, + response = ToscaServiceTemplate.class, + responseHeaders = { + @ResponseHeader(name = "X-MinorVersion", + description = "Used to request or communicate a MINOR version back from the client" + + " to the server, and from the server back to the client", + response = String.class), + @ResponseHeader(name = "X-PatchVersion", + description = "Used only to communicate a PATCH version in a response for" + + " troubleshooting purposes only, and will not be provided by" + " the client on request", + response = String.class), + @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version", + response = String.class), + @ResponseHeader(name = "X-ONAP-RequestID", + description = "Used to track REST transactions for logging purpose", response = UUID.class)}, + extensions = { + @Extension(name = "interface info", properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"), + @ExtensionProperty(name = "last-mod-release", value = "Dublin")})}) + @ApiResponses(value = {@ApiResponse(code = 400, message = "Invalid Body"), + @ApiResponse(code = 401, message = "Authentication Error"), + @ApiResponse(code = 403, message = "Authorization Error"), + @ApiResponse(code = 406, message = "Not Acceptable Payload"), + @ApiResponse(code = 500, message = "Internal Server Error")}) public Response createPolicyType( - @ApiParam(value = "Entity body of policy type", required = true) ToscaServiceTemplate body, - @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) { + @ApiParam(value = "Entity body of policy type", required = true) ToscaServiceTemplate body, + @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) { if (NetLoggerUtil.getNetworkLogger().isInfoEnabled()) { NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, "/policytypes", toJson(body)); @@ -426,37 +418,36 @@ public class ApiRestController extends CommonRestController { @DELETE @Path("/policytypes/{policyTypeId}/versions/{versionId}") @ApiOperation(value = "Delete one version of a policy type", - notes = "Rule 1: pre-defined policy types cannot be deleted;" - + "Rule 2: policy types that are in use (parameterized by a TOSCA policy) cannot be deleted." - + "The parameterizing TOSCA policies must be deleted first;", - authorizations = @Authorization(value = "basicAuth"), tags = {"PolicyType",}, - response = ToscaServiceTemplate.class, - responseHeaders = { - @ResponseHeader(name = "X-MinorVersion", - description = "Used to request or communicate a MINOR version back from the client" - + " to the server, and from the server back to the client", - response = String.class), - @ResponseHeader(name = "X-PatchVersion", - description = "Used only to communicate a PATCH version in a response for" - + " troubleshooting purposes only, and will not be provided by" - + " the client on request", - response = String.class), - @ResponseHeader(name = "X-LatestVersion", - description = "Used only to communicate an API's latest version", response = String.class), - @ResponseHeader(name = "X-ONAP-RequestID", - description = "Used to track REST transactions for logging purpose", response = UUID.class)}, - extensions = {@Extension(name = "interface info", - properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"), - @ExtensionProperty(name = "last-mod-release", value = "Dublin")})}) + notes = "Rule 1: pre-defined policy types cannot be deleted;" + + "Rule 2: policy types that are in use (parameterized by a TOSCA policy) cannot be deleted." + + "The parameterizing TOSCA policies must be deleted first;", + authorizations = @Authorization(value = "basicAuth"), tags = {"PolicyType",}, + response = ToscaServiceTemplate.class, + responseHeaders = { + @ResponseHeader(name = "X-MinorVersion", + description = "Used to request or communicate a MINOR version back from the client" + + " to the server, and from the server back to the client", + response = String.class), + @ResponseHeader(name = "X-PatchVersion", + description = "Used only to communicate a PATCH version in a response for" + + " troubleshooting purposes only, and will not be provided by" + " the client on request", + response = String.class), + @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version", + response = String.class), + @ResponseHeader(name = "X-ONAP-RequestID", + description = "Used to track REST transactions for logging purpose", response = UUID.class)}, + extensions = { + @Extension(name = "interface info", properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"), + @ExtensionProperty(name = "last-mod-release", value = "Dublin")})}) @ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"), @ApiResponse(code = 403, message = "Authorization Error"), @ApiResponse(code = 404, message = "Resource Not Found"), @ApiResponse(code = 409, message = "Delete Conflict, Rule Violation"), @ApiResponse(code = 500, message = "Internal Server Error")}) public Response deleteSpecificVersionOfPolicyType( - @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId, - @PathParam("versionId") @ApiParam(value = "Version of policy type", required = true) String versionId, - @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) { + @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId, + @PathParam("versionId") @ApiParam(value = "Version of policy type", required = true) String versionId, + @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) { try (PolicyTypeProvider policyTypeProvider = new PolicyTypeProvider()) { ToscaServiceTemplate serviceTemplate = policyTypeProvider.deletePolicyType(policyTypeId, versionId); @@ -475,42 +466,52 @@ public class ApiRestController extends CommonRestController { * * @return the Response object containing the results of the API operation */ + // @formatter:off @GET @Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies") - @ApiOperation(value = "Retrieve all versions of a policy created for a particular policy type version", - notes = "Returns a list of all versions of specified policy created for the specified policy type version", - response = ToscaServiceTemplate.class, - responseHeaders = { - @ResponseHeader(name = "X-MinorVersion", - description = "Used to request or communicate a MINOR version back from the client" - + " to the server, and from the server back to the client", - response = String.class), - @ResponseHeader(name = "X-PatchVersion", - description = "Used only to communicate a PATCH version in a response for" - + " troubleshooting purposes only, and will not be provided by" - + " the client on request", - response = String.class), - @ResponseHeader(name = "X-LatestVersion", - description = "Used only to communicate an API's latest version", response = String.class), - @ResponseHeader(name = "X-ONAP-RequestID", - description = "Used to track REST transactions for logging purpose", response = UUID.class)}, - authorizations = @Authorization(value = "basicAuth"), tags = {"Policy",}, - extensions = {@Extension(name = "interface info", - properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"), - @ExtensionProperty(name = "last-mod-release", value = "Dublin")})}) - @ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"), + @ApiOperation( + value = "Retrieve all versions of a policy created for a particular policy type version", + notes = "Returns a list of all versions of specified policy created for the specified policy type version", + response = ToscaServiceTemplate.class, + responseHeaders = { + @ResponseHeader(name = "X-MinorVersion", + description = "Used to request or communicate a MINOR version back from the client" + + " to the server, and from the server back to the client", + response = String.class), + @ResponseHeader(name = "X-PatchVersion", + description = "Used only to communicate a PATCH version in a response for" + + " troubleshooting purposes only, and will not be provided by" + " the client on request", + response = String.class), + @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version", + response = String.class), + @ResponseHeader(name = "X-ONAP-RequestID", + description = "Used to track REST transactions for logging purpose", response = UUID.class)}, + authorizations = @Authorization(value = "basicAuth"), tags = {"Policy,"}, + extensions = { + @Extension(name = "interface info", properties = { + @ExtensionProperty(name = "api-version", value = "1.0.0"), + @ExtensionProperty(name = "last-mod-release", value = "Dublin") + }) + } + ) + @ApiResponses(value = { + @ApiResponse(code = 401, message = "Authentication Error"), @ApiResponse(code = 403, message = "Authorization Error"), @ApiResponse(code = 404, message = "Resource Not Found"), - @ApiResponse(code = 500, message = "Internal Server Error")}) + @ApiResponse(code = 500, message = "Internal Server Error") + }) public Response getAllPolicies( - @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId, - @PathParam("policyTypeVersion") @ApiParam(value = "Version of policy type", - required = true) String policyTypeVersion, - @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) { + @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId, + @PathParam("policyTypeVersion") @ApiParam(value = "Version of policy type", + required = true) String policyTypeVersion, + @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId, + @QueryParam("mode") @DefaultValue("bare") @ApiParam("Fetch mode for policies, BARE for bare policies (default)," + + " REFERENCED for fully referenced policies") PolicyFetchMode mode + ) { try (PolicyProvider policyProvider = new PolicyProvider()) { ToscaServiceTemplate serviceTemplate = - policyProvider.fetchPolicies(policyTypeId, policyTypeVersion, null, null); + policyProvider.fetchPolicies(policyTypeId, policyTypeVersion, null, null, mode); updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.GET); return makeOkResponse(requestId, serviceTemplate); } catch (PfModelException | PfModelRuntimeException pfme) { @@ -519,6 +520,7 @@ public class ApiRestController extends CommonRestController { return makeErrorResponse(requestId, pfme); } } + // @formatter:on /** * Retrieves all versions of a particular policy. @@ -529,43 +531,50 @@ public class ApiRestController extends CommonRestController { * * @return the Response object containing the results of the API operation */ + // @formatter:off @GET @Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}") @ApiOperation(value = "Retrieve all version details of a policy created for a particular policy type version", - notes = "Returns a list of all version details of the specified policy", - response = ToscaServiceTemplate.class, - responseHeaders = { - @ResponseHeader(name = "X-MinorVersion", - description = "Used to request or communicate a MINOR version back from the client" - + " to the server, and from the server back to the client", - response = String.class), - @ResponseHeader(name = "X-PatchVersion", - description = "Used only to communicate a PATCH version in a response for" - + " troubleshooting purposes only, and will not be provided by" - + " the client on request", - response = String.class), - @ResponseHeader(name = "X-LatestVersion", - description = "Used only to communicate an API's latest version", response = String.class), - @ResponseHeader(name = "X-ONAP-RequestID", - description = "Used to track REST transactions for logging purpose", response = UUID.class)}, - authorizations = @Authorization(value = "basicAuth"), tags = {"Policy",}, - extensions = {@Extension(name = "interface info", - properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"), - @ExtensionProperty(name = "last-mod-release", value = "Dublin")})}) - @ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"), + notes = "Returns a list of all version details of the specified policy", response = ToscaServiceTemplate.class, + responseHeaders = { + @ResponseHeader(name = "X-MinorVersion", + description = "Used to request or communicate a MINOR version back from the client" + + " to the server, and from the server back to the client", + response = String.class), + @ResponseHeader(name = "X-PatchVersion", + description = "Used only to communicate a PATCH version in a response for" + + " troubleshooting purposes only, and will not be provided by" + " the client on request", + response = String.class), + @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version", + response = String.class), + @ResponseHeader(name = "X-ONAP-RequestID", + description = "Used to track REST transactions for logging purpose", response = UUID.class)}, + authorizations = @Authorization(value = "basicAuth"), tags = {"Policy",}, + extensions = { + @Extension(name = "interface info", properties = { + @ExtensionProperty(name = "api-version", value = "1.0.0"), + @ExtensionProperty(name = "last-mod-release", value = "Dublin") + }) + } + ) + @ApiResponses(value = { + @ApiResponse(code = 401, message = "Authentication Error"), @ApiResponse(code = 403, message = "Authorization Error"), @ApiResponse(code = 404, message = "Resource Not Found"), - @ApiResponse(code = 500, message = "Internal Server Error")}) + @ApiResponse(code = 500, message = "Internal Server Error") + }) public Response getAllVersionsOfPolicy( - @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId, - @PathParam("policyTypeVersion") @ApiParam(value = "Version of policy type", - required = true) String policyTypeVersion, - @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId, - @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) { - + @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId, + @PathParam("policyTypeVersion") @ApiParam(value = "Version of policy type", + required = true) String policyTypeVersion, + @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId, + @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId, + @QueryParam("mode") @DefaultValue("bare") @ApiParam("Fetch mode for policies, BARE for bare policies (default)," + + " REFERENCED for fully referenced policies") PolicyFetchMode mode + ) { try (PolicyProvider policyProvider = new PolicyProvider()) { ToscaServiceTemplate serviceTemplate = - policyProvider.fetchPolicies(policyTypeId, policyTypeVersion, policyId, null); + policyProvider.fetchPolicies(policyTypeId, policyTypeVersion, policyId, null, mode); updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.GET); return makeOkResponse(requestId, serviceTemplate); } catch (PfModelException | PfModelRuntimeException pfme) { @@ -574,6 +583,7 @@ public class ApiRestController extends CommonRestController { return makeErrorResponse(requestId, pfme); } } + // @formatter:on /** * Retrieves the specified version of a particular policy. @@ -585,53 +595,62 @@ public class ApiRestController extends CommonRestController { * * @return the Response object containing the results of the API operation */ + // @formatter:off @GET @Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}/versions/{policyVersion}") @ApiOperation(value = "Retrieve one version of a policy created for a particular policy type version", - notes = "Returns a particular version of specified policy created for the specified policy type version", - response = ToscaServiceTemplate.class, - responseHeaders = { - @ResponseHeader(name = "X-MinorVersion", - description = "Used to request or communicate a MINOR version back from the client" - + " to the server, and from the server back to the client", - response = String.class), - @ResponseHeader(name = "X-PatchVersion", - description = "Used only to communicate a PATCH version in a response for" - + " troubleshooting purposes only, and will not be provided by" - + " the client on request", - response = String.class), - @ResponseHeader(name = "X-LatestVersion", - description = "Used only to communicate an API's latest version", response = String.class), - @ResponseHeader(name = "X-ONAP-RequestID", - description = "Used to track REST transactions for logging purpose", response = UUID.class)}, - authorizations = @Authorization(value = "basicAuth"), tags = {"Policy",}, - extensions = {@Extension(name = "interface info", - properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"), - @ExtensionProperty(name = "last-mod-release", value = "Dublin")})}) - @ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"), + notes = "Returns a particular version of specified policy created for the specified policy type version", + response = ToscaServiceTemplate.class, + responseHeaders = { + @ResponseHeader(name = "X-MinorVersion", + description = "Used to request or communicate a MINOR version back from the client" + + " to the server, and from the server back to the client", + response = String.class), + @ResponseHeader(name = "X-PatchVersion", + description = "Used only to communicate a PATCH version in a response for" + + " troubleshooting purposes only, and will not be provided by" + " the client on request", + response = String.class), + @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version", + response = String.class), + @ResponseHeader(name = "X-ONAP-RequestID", + description = "Used to track REST transactions for logging purpose", response = UUID.class)}, + authorizations = @Authorization(value = "basicAuth"), tags = {"Policy",}, + extensions = { + @Extension(name = "interface info", properties = { + @ExtensionProperty(name = "api-version", value = "1.0.0"), + @ExtensionProperty(name = "last-mod-release", value = "Dublin") + }) + } + ) + @ApiResponses(value = { + @ApiResponse(code = 401, message = "Authentication Error"), @ApiResponse(code = 403, message = "Authorization Error"), @ApiResponse(code = 404, message = "Resource Not Found"), - @ApiResponse(code = 500, message = "Internal Server Error")}) + @ApiResponse(code = 500, message = "Internal Server Error") + }) public Response getSpecificVersionOfPolicy( - @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId, - @PathParam("policyTypeVersion") @ApiParam(value = "Version of policy type", - required = true) String policyTypeVersion, - @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId, - @PathParam("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion, - @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) { - + @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId, + @PathParam("policyTypeVersion") @ApiParam(value = "Version of policy type", + required = true) String policyTypeVersion, + @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId, + @PathParam("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion, + @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId, + @QueryParam("mode") @DefaultValue("bare") @ApiParam("Fetch mode for policies, BARE for bare policies (default)," + + " REFERENCED for fully referenced policies") PolicyFetchMode mode + ) { try (PolicyProvider policyProvider = new PolicyProvider()) { ToscaServiceTemplate serviceTemplate = - policyProvider.fetchPolicies(policyTypeId, policyTypeVersion, policyId, policyVersion); + policyProvider.fetchPolicies(policyTypeId, policyTypeVersion, policyId, policyVersion, mode); updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.GET); return makeOkResponse(requestId, serviceTemplate); } catch (PfModelException | PfModelRuntimeException pfme) { LOGGER.debug("GET /policytypes/{}/versions/{}/policies/{}/versions/{}", policyTypeId, policyTypeVersion, - policyId, policyVersion, pfme); + policyId, policyVersion, pfme); updateApiStatisticsCounter(Target.POLICY, Result.FAILURE, HttpMethod.GET); return makeErrorResponse(requestId, pfme); } } + // @formatter:on /** * Retrieves the latest version of a particular policy. @@ -645,44 +664,45 @@ public class ApiRestController extends CommonRestController { @GET @Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}/versions/latest") @ApiOperation(value = "Retrieve the latest version of a particular policy", - notes = "Returns the latest version of specified policy", response = ToscaServiceTemplate.class, - responseHeaders = { - @ResponseHeader(name = "X-MinorVersion", - description = "Used to request or communicate a MINOR version back from the client" - + " to the server, and from the server back to the client", - response = String.class), - @ResponseHeader(name = "X-PatchVersion", - description = "Used only to communicate a PATCH version in a response for" - + " troubleshooting purposes only, and will not be provided by" - + " the client on request", - response = String.class), - @ResponseHeader(name = "X-LatestVersion", - description = "Used only to communicate an API's latest version", response = String.class), - @ResponseHeader(name = "X-ONAP-RequestID", - description = "Used to track REST transactions for logging purpose", response = UUID.class)}, - authorizations = @Authorization(value = "basicAuth"), tags = {"Policy",}, - extensions = {@Extension(name = "interface info", - properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"), - @ExtensionProperty(name = "last-mod-release", value = "Dublin")})}) + notes = "Returns the latest version of specified policy", response = ToscaServiceTemplate.class, + responseHeaders = { + @ResponseHeader(name = "X-MinorVersion", + description = "Used to request or communicate a MINOR version back from the client" + + " to the server, and from the server back to the client", + response = String.class), + @ResponseHeader(name = "X-PatchVersion", + description = "Used only to communicate a PATCH version in a response for" + + " troubleshooting purposes only, and will not be provided by" + " the client on request", + response = String.class), + @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version", + response = String.class), + @ResponseHeader(name = "X-ONAP-RequestID", + description = "Used to track REST transactions for logging purpose", response = UUID.class)}, + authorizations = @Authorization(value = "basicAuth"), tags = {"Policy",}, + extensions = { + @Extension(name = "interface info", properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"), + @ExtensionProperty(name = "last-mod-release", value = "Dublin")})}) @ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"), @ApiResponse(code = 403, message = "Authorization Error"), @ApiResponse(code = 404, message = "Resource Not Found"), @ApiResponse(code = 500, message = "Internal Server Error")}) public Response getLatestVersionOfPolicy( - @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId, - @PathParam("policyTypeVersion") @ApiParam(value = "Version of policy type", - required = true) String policyTypeVersion, - @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId, - @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) { + @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId, + @PathParam("policyTypeVersion") @ApiParam(value = "Version of policy type", + required = true) String policyTypeVersion, + @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId, + @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId, + @QueryParam("mode") @ApiParam("Fetch mode for policies, TERSE for bare policies (default), " + + "REFERENCED for fully referenced policies") PolicyFetchMode mode) { try (PolicyProvider policyProvider = new PolicyProvider()) { ToscaServiceTemplate serviceTemplate = - policyProvider.fetchLatestPolicies(policyTypeId, policyTypeVersion, policyId); + policyProvider.fetchLatestPolicies(policyTypeId, policyTypeVersion, policyId, mode); updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.GET); return makeOkResponse(requestId, serviceTemplate); } catch (PfModelException | PfModelRuntimeException pfme) { LOGGER.debug("GET /policytypes/{}/versions/{}/policies/{}/versions/latest", policyTypeId, policyTypeVersion, - policyId, pfme); + policyId, pfme); updateApiStatisticsCounter(Target.POLICY, Result.FAILURE, HttpMethod.GET); return makeErrorResponse(requestId, pfme); } @@ -700,50 +720,40 @@ public class ApiRestController extends CommonRestController { @POST @Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies") @ApiOperation(value = "Create a new policy for a policy type version", - notes = "Client should provide TOSCA body of the new policy", - authorizations = @Authorization(value = "basicAuth"), tags = {"Policy",}, - response = ToscaServiceTemplate.class, - responseHeaders = { - @ResponseHeader(name = "X-MinorVersion", - description = "Used to request or communicate a MINOR version back from the client" - + " to the server, and from the server back to the client", - response = String.class), - @ResponseHeader(name = "X-PatchVersion", - description = "Used only to communicate a PATCH version in a response for" - + " troubleshooting purposes only, and will not be provided by" - + " the client on request", - response = String.class), - @ResponseHeader(name = "X-LatestVersion", - description = "Used only to communicate an API's latest version", - response = String.class), - @ResponseHeader(name = "X-ONAP-RequestID", - description = "Used to track REST transactions for logging purpose", - response = UUID.class) - }, - extensions = { - @Extension(name = "interface info", properties = { - @ExtensionProperty(name = "api-version", value = "1.0.0"), - @ExtensionProperty(name = "last-mod-release", value = "Dublin") - }) - }) - @ApiResponses(value = { - @ApiResponse(code = 400, message = "Invalid Body"), - @ApiResponse(code = 401, message = "Authentication Error"), - @ApiResponse(code = 403, message = "Authorization Error"), - @ApiResponse(code = 404, message = "Resource Not Found"), - @ApiResponse(code = 406, message = "Not Acceptable Payload"), - @ApiResponse(code = 500, message = "Internal Server Error") - }) + notes = "Client should provide TOSCA body of the new policy", + authorizations = @Authorization(value = "basicAuth"), tags = {"Policy",}, response = ToscaServiceTemplate.class, + responseHeaders = { + @ResponseHeader(name = "X-MinorVersion", + description = "Used to request or communicate a MINOR version back from the client" + + " to the server, and from the server back to the client", + response = String.class), + @ResponseHeader(name = "X-PatchVersion", + description = "Used only to communicate a PATCH version in a response for" + + " troubleshooting purposes only, and will not be provided by" + " the client on request", + response = String.class), + @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version", + response = String.class), + @ResponseHeader(name = "X-ONAP-RequestID", + description = "Used to track REST transactions for logging purpose", response = UUID.class)}, + extensions = { + @Extension(name = "interface info", properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"), + @ExtensionProperty(name = "last-mod-release", value = "Dublin")})}) + @ApiResponses(value = {@ApiResponse(code = 400, message = "Invalid Body"), + @ApiResponse(code = 401, message = "Authentication Error"), + @ApiResponse(code = 403, message = "Authorization Error"), + @ApiResponse(code = 404, message = "Resource Not Found"), + @ApiResponse(code = 406, message = "Not Acceptable Payload"), + @ApiResponse(code = 500, message = "Internal Server Error")}) public Response createPolicy( - @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId, - @PathParam("policyTypeVersion") @ApiParam(value = "Version of policy type", - required = true) String policyTypeVersion, - @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId, - @ApiParam(value = "Entity body of policy", required = true) ToscaServiceTemplate body) { + @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId, + @PathParam("policyTypeVersion") @ApiParam(value = "Version of policy type", + required = true) String policyTypeVersion, + @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId, + @ApiParam(value = "Entity body of policy", required = true) ToscaServiceTemplate body) { if (NetLoggerUtil.getNetworkLogger().isInfoEnabled()) { NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, - "/policytypes/" + policyTypeId + "/versions/" + policyTypeVersion + "/policies", toJson(body)); + "/policytypes/" + policyTypeId + "/versions/" + policyTypeVersion + "/policies", toJson(body)); } try (PolicyProvider policyProvider = new PolicyProvider()) { @@ -767,43 +777,33 @@ public class ApiRestController extends CommonRestController { @POST @Path("/policies") @ApiOperation(value = "Create one or more new policies", - notes = "Client should provide TOSCA body of the new polic(ies)", - authorizations = @Authorization(value = "basicAuth"), tags = {"Policy",}, - response = ToscaServiceTemplate.class, - responseHeaders = { - @ResponseHeader(name = "X-MinorVersion", - description = "Used to request or communicate a MINOR version back from the client" - + " to the server, and from the server back to the client", - response = String.class), - @ResponseHeader(name = "X-PatchVersion", - description = "Used only to communicate a PATCH version in a response for" - + " troubleshooting purposes only, and will not be provided by" - + " the client on request", - response = String.class), - @ResponseHeader(name = "X-LatestVersion", - description = "Used only to communicate an API's latest version", - response = String.class), - @ResponseHeader(name = "X-ONAP-RequestID", - description = "Used to track REST transactions for logging purpose", - response = UUID.class) - }, - extensions = { - @Extension(name = "interface info", properties = { - @ExtensionProperty(name = "api-version", value = "1.0.0"), - @ExtensionProperty(name = "last-mod-release", value = "El Alto") - }) - }) - @ApiResponses(value = { - @ApiResponse(code = 400, message = "Invalid Body"), - @ApiResponse(code = 401, message = "Authentication Error"), - @ApiResponse(code = 403, message = "Authorization Error"), - @ApiResponse(code = 404, message = "Resource Not Found"), - @ApiResponse(code = 406, message = "Not Acceptable Payload"), - @ApiResponse(code = 500, message = "Internal Server Error") - }) + notes = "Client should provide TOSCA body of the new polic(ies)", + authorizations = @Authorization(value = "basicAuth"), tags = {"Policy",}, response = ToscaServiceTemplate.class, + responseHeaders = { + @ResponseHeader(name = "X-MinorVersion", + description = "Used to request or communicate a MINOR version back from the client" + + " to the server, and from the server back to the client", + response = String.class), + @ResponseHeader(name = "X-PatchVersion", + description = "Used only to communicate a PATCH version in a response for" + + " troubleshooting purposes only, and will not be provided by" + " the client on request", + response = String.class), + @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version", + response = String.class), + @ResponseHeader(name = "X-ONAP-RequestID", + description = "Used to track REST transactions for logging purpose", response = UUID.class)}, + extensions = { + @Extension(name = "interface info", properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"), + @ExtensionProperty(name = "last-mod-release", value = "El Alto")})}) + @ApiResponses(value = {@ApiResponse(code = 400, message = "Invalid Body"), + @ApiResponse(code = 401, message = "Authentication Error"), + @ApiResponse(code = 403, message = "Authorization Error"), + @ApiResponse(code = 404, message = "Resource Not Found"), + @ApiResponse(code = 406, message = "Not Acceptable Payload"), + @ApiResponse(code = 500, message = "Internal Server Error")}) public Response createPolicies( - @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId, - @ApiParam(value = "Entity body of policy", required = true) ToscaServiceTemplate body) { + @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId, + @ApiParam(value = "Entity body of policy", required = true) ToscaServiceTemplate body) { if (NetLoggerUtil.getNetworkLogger().isInfoEnabled()) { NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, "/policies", toJson(body)); @@ -833,46 +833,44 @@ public class ApiRestController extends CommonRestController { @DELETE @Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}/versions/{policyVersion}") @ApiOperation(value = "Delete a particular version of a policy", - notes = "Rule: the version that has been deployed in PDP group(s) cannot be deleted", - authorizations = @Authorization(value = "basicAuth"), tags = {"Policy",}, - response = ToscaServiceTemplate.class, - responseHeaders = { - @ResponseHeader(name = "X-MinorVersion", - description = "Used to request or communicate a MINOR version back from the client" - + " to the server, and from the server back to the client", - response = String.class), - @ResponseHeader(name = "X-PatchVersion", - description = "Used only to communicate a PATCH version in a response for" - + " troubleshooting purposes only, and will not be provided by" - + " the client on request", - response = String.class), - @ResponseHeader(name = "X-LatestVersion", - description = "Used only to communicate an API's latest version", response = String.class), - @ResponseHeader(name = "X-ONAP-RequestID", - description = "Used to track REST transactions for logging purpose", response = UUID.class)}, - extensions = {@Extension(name = "interface info", - properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"), - @ExtensionProperty(name = "last-mod-release", value = "Dublin")})}) + notes = "Rule: the version that has been deployed in PDP group(s) cannot be deleted", + authorizations = @Authorization(value = "basicAuth"), tags = {"Policy",}, response = ToscaServiceTemplate.class, + responseHeaders = { + @ResponseHeader(name = "X-MinorVersion", + description = "Used to request or communicate a MINOR version back from the client" + + " to the server, and from the server back to the client", + response = String.class), + @ResponseHeader(name = "X-PatchVersion", + description = "Used only to communicate a PATCH version in a response for" + + " troubleshooting purposes only, and will not be provided by" + " the client on request", + response = String.class), + @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version", + response = String.class), + @ResponseHeader(name = "X-ONAP-RequestID", + description = "Used to track REST transactions for logging purpose", response = UUID.class)}, + extensions = { + @Extension(name = "interface info", properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"), + @ExtensionProperty(name = "last-mod-release", value = "Dublin")})}) @ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"), @ApiResponse(code = 403, message = "Authorization Error"), @ApiResponse(code = 404, message = "Resource Not Found"), @ApiResponse(code = 409, message = "Delete Conflict, Rule Violation"), @ApiResponse(code = 500, message = "Internal Server Error")}) public Response deleteSpecificVersionOfPolicy( - @PathParam("policyTypeId") @ApiParam(value = "PolicyType ID", required = true) String policyTypeId, - @PathParam("policyTypeVersion") @ApiParam(value = "Version of policy type", - required = true) String policyTypeVersion, - @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId, - @PathParam("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion, - @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) { + @PathParam("policyTypeId") @ApiParam(value = "PolicyType ID", required = true) String policyTypeId, + @PathParam("policyTypeVersion") @ApiParam(value = "Version of policy type", + required = true) String policyTypeVersion, + @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId, + @PathParam("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion, + @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) { try (PolicyProvider policyProvider = new PolicyProvider()) { ToscaServiceTemplate serviceTemplate = - policyProvider.deletePolicy(policyTypeId, policyTypeVersion, policyId, policyVersion); + policyProvider.deletePolicy(policyTypeId, policyTypeVersion, policyId, policyVersion); return makeOkResponse(requestId, serviceTemplate); } catch (PfModelException | PfModelRuntimeException pfme) { LOGGER.debug("DELETE /policytypes/{}/versions/{}/policies/{}/versions/{}", policyTypeId, policyTypeVersion, - policyId, policyVersion, pfme); + policyId, policyVersion, pfme); return makeErrorResponse(requestId, pfme); } }