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=67baa8a4c681705c8227d111723969046872e6f1;hb=c0feaca7b641f6c0e3214f5333a1493c9893e0cb;hp=8c3d55ff968113e7561882be0a8663da056ddc01;hpb=20390c6ed94e2082cb688d76aacabe5366d908fe;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 8c3d55ff..67baa8a4 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 @@ -938,6 +938,69 @@ public class ApiRestController extends CommonRestController { } } + /** + * Creates one or more new policies in one call. + * + * @param body the body of policy following TOSCA definition + * + * @return the Response object containing the results of the API operation + */ + @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 = 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) { + + if (NetLoggerUtil.getNetworkLogger().isInfoEnabled()) { + NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, "/policies", toJson(body)); + } + + try (PolicyProvider policyProvider = new PolicyProvider()) { + ToscaServiceTemplate serviceTemplate = policyProvider.createPolicies(body); + updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.POST); + return makeOkResponse(requestId, serviceTemplate); + } catch (PfModelException | PfModelRuntimeException pfme) { + LOGGER.error("POST /policies", pfme); + updateApiStatisticsCounter(Target.POLICY, Result.FAILURE, HttpMethod.POST); + return makeErrorResponse(requestId, pfme); + } + } + /** * Deletes the specified version of a particular policy. *