Created a new simplified API for creating policies
[policy/api.git] / main / src / main / java / org / onap / policy / api / main / rest / ApiRestController.java
index 8c3d55f..67baa8a 100644 (file)
@@ -938,6 +938,69 @@ public class ApiRestController extends CommonRestController {
         }\r
     }\r
 \r
+    /**\r
+     * Creates one or more new policies in one call.\r
+     *\r
+     * @param body the body of policy following TOSCA definition\r
+     *\r
+     * @return the Response object containing the results of the API operation\r
+     */\r
+    @POST\r
+    @Path("/policies")\r
+    @ApiOperation(value = "Create one or more new policies",\r
+            notes = "Client should provide TOSCA body of the new polic(ies)",\r
+            authorizations = @Authorization(value = "basicAuth"),\r
+            tags = { "Policy", },\r
+            response = ToscaServiceTemplate.class,\r
+            responseHeaders = {\r
+                    @ResponseHeader(name = "X-MinorVersion",\r
+                                    description = "Used to request or communicate a MINOR version back from the client"\r
+                                                + " to the server, and from the server back to the client",\r
+                                    response = String.class),\r
+                    @ResponseHeader(name = "X-PatchVersion",\r
+                                    description = "Used only to communicate a PATCH version in a response for"\r
+                                                + " troubleshooting purposes only, and will not be provided by"\r
+                                                + " the client on request",\r
+                                    response = String.class),\r
+                    @ResponseHeader(name = "X-LatestVersion",\r
+                                    description = "Used only to communicate an API's latest version",\r
+                                    response = String.class),\r
+                    @ResponseHeader(name = "X-ONAP-RequestID",\r
+                                    description = "Used to track REST transactions for logging purpose",\r
+                                    response = UUID.class)\r
+            },\r
+            extensions = {\r
+                    @Extension(name = "interface info", properties = {\r
+                            @ExtensionProperty(name = "api-version", value = "1.0.0"),\r
+                            @ExtensionProperty(name = "last-mod-release", value = "El Alto")\r
+                    })\r
+            })\r
+    @ApiResponses(value = {\r
+            @ApiResponse(code = 400, message = "Invalid Body"),\r
+            @ApiResponse(code = 401, message = "Authentication Error"),\r
+            @ApiResponse(code = 403, message = "Authorization Error"),\r
+            @ApiResponse(code = 404, message = "Resource Not Found"),\r
+            @ApiResponse(code = 500, message = "Internal Server Error")\r
+        })\r
+    public Response createPolicies(\r
+            @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId,\r
+            @ApiParam(value = "Entity body of policy", required = true) ToscaServiceTemplate body) {\r
+\r
+        if (NetLoggerUtil.getNetworkLogger().isInfoEnabled()) {\r
+            NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, "/policies", toJson(body));\r
+        }\r
+\r
+        try (PolicyProvider policyProvider = new PolicyProvider()) {\r
+            ToscaServiceTemplate serviceTemplate = policyProvider.createPolicies(body);\r
+            updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.POST);\r
+            return makeOkResponse(requestId, serviceTemplate);\r
+        } catch (PfModelException | PfModelRuntimeException pfme) {\r
+            LOGGER.error("POST /policies", pfme);\r
+            updateApiStatisticsCounter(Target.POLICY, Result.FAILURE, HttpMethod.POST);\r
+            return makeErrorResponse(requestId, pfme);\r
+        }\r
+    }\r
+\r
     /**\r
      * Deletes the specified version of a particular policy.\r
      *\r