+
+ /**
+ * Retrieves all available policy types.
+ *
+ * @return the Response object containing the results of the API operation
+ */
+ @GET
+ @Path("/policytypes")
+ @ApiOperation(value = "Retrieve existing policy types",
+ notes = "Returns a list of existing policy types stored in Policy Framework",
+ response = ToscaPolicyTypeList.class,
+ authorizations = @Authorization(value = "basicAuth"),
+ tags = { "PolicyType", })
+ @ApiResponses(value = {
+ @ApiResponse(code = 401, message = "Authentication Error"),
+ @ApiResponse(code = 403, message = "Authorization Error"),
+ @ApiResponse(code = 500, message = "Internal Server Error")
+ })
+ public Response getAllPolicyTypes() {
+ return Response.status(Response.Status.OK)
+ .entity(new PolicyTypeProvider().fetchPolicyTypes(null, null)).build();
+ }
+
+ /**
+ * Retrieves all versions of a particular policy type.
+ *
+ * @param policyTypeId the ID of specified policy type
+ *
+ * @return the Response object containing the results of the API operation
+ */
+ @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 = ToscaPolicyTypeList.class,
+ authorizations = @Authorization(value = "basicAuth"),
+ tags = { "PolicyType", })
+ @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("ID of policy type") String policyTypeId) {
+ return Response.status(Response.Status.OK)
+ .entity(new PolicyTypeProvider().fetchPolicyTypes(policyTypeId, null)).build();
+ }
+
+ /**
+ * Retrieves specified version of a particular policy type.
+ *
+ * @param policyTypeId the ID of specified policy type
+ * @param versionId the version of specified policy type
+ *
+ * @return the Response object containing the results of the API operation
+ */
+ @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 = ToscaPolicyTypeList.class,
+ authorizations = @Authorization(value = "basicAuth"),
+ tags = { "PolicyType", })
+ @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("ID of policy type") String policyTypeId,
+ @PathParam("versionId") @ApiParam("ID of version") String versionId) {
+ return Response.status(Response.Status.OK)
+ .entity(new PolicyTypeProvider().fetchPolicyTypes(policyTypeId, versionId)).build();
+ }
+
+ /**
+ * Creates a new policy type.
+ *
+ * @param body the body of policy type following TOSCA definition
+ *
+ * @return the Response object containing the results of the API operation
+ */
+ @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", })
+ @ApiResponses(value = {
+ @ApiResponse(code = 400, message = "Invalid Body"),
+ @ApiResponse(code = 401, message = "Authentication Error"),
+ @ApiResponse(code = 403, message = "Authorization Error"),
+ @ApiResponse(code = 500, message = "Internal Server Error")
+ })
+ public Response createPolicyType(ToscaPolicyType body) {
+ return Response.status(Response.Status.OK).entity(new PolicyTypeProvider().createPolicyType(body)).build();
+ }
+
+ /**
+ * Deletes all versions of a particular policy type.
+ *
+ * @param policyTypeId the ID of specified policy type
+ *
+ * @return the Response object containing the results of the API operation
+ */
+ @DELETE
+ @Path("/policytypes/{policyTypeId}")
+ @ApiOperation(value = "Delete all versions 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", })
+ @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 deleteAllVersionsOfPolicyType(
+ @PathParam("policyTypeId") @ApiParam("ID of policy type") String policyTypeId) {
+ return Response.status(Response.Status.OK)
+ .entity(new PolicyTypeProvider().deletePolicyTypes(policyTypeId, null)).build();
+ }
+
+ /**
+ * Deletes specified version of a particular policy type.
+ *
+ * @param policyTypeId the ID of specified policy type
+ * @param versionId the version of specified policy type
+ *
+ * @return the Response object containing the results of the API operation
+ */
+ @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", })
+ @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("ID of policy type") String policyTypeId,
+ @PathParam("versionId") @ApiParam("ID of version") String versionId) {
+ return Response.status(Response.Status.OK)
+ .entity(new PolicyTypeProvider().deletePolicyTypes(policyTypeId, versionId)).build();
+ }
+
+ /**
+ * Retrieves all versions of a particular policy.
+ *
+ * @param policyTypeId the ID of specified policy type
+ * @param policyTypeVersion the version of specified policy type
+ *
+ * @return the Response object containing the results of the API operation
+ */
+ @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 = ToscaPolicyList.class,
+ authorizations = @Authorization(value = "basicAuth"),
+ tags = { "Policy", })
+ @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 getAllPolicies(
+ @PathParam("policyTypeId") @ApiParam("ID of policy type") String policyTypeId,
+ @PathParam("policyTypeVersion") @ApiParam("ID of policy type version") String policyTypeVersion) {
+ return Response.status(Response.Status.OK)
+ .entity(new PolicyProvider().fetchPolicies(policyTypeId, policyTypeVersion, null, null)).build();
+ }
+
+ /**
+ * Retrieves all versions of a particular policy.
+ *
+ * @param policyTypeId the ID of specified policy type
+ * @param policyTypeVersion the version of specified policy type
+ * @param policyId the ID of specified policy
+ *
+ * @return the Response object containing the results of the API operation
+ */
+ @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 = ToscaPolicyList.class,
+ authorizations = @Authorization(value = "basicAuth"),
+ tags = { "Policy", })
+ @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 getAllVersionsOfPolicy(
+ @PathParam("policyTypeId") @ApiParam("ID of policy type") String policyTypeId,
+ @PathParam("policyTypeVersion") @ApiParam("ID of policy type version") String policyTypeVersion,
+ @PathParam("policyId") @ApiParam("ID of policy") String policyId) {
+ return Response.status(Response.Status.OK)
+ .entity(new PolicyProvider().fetchPolicies(policyTypeId, policyTypeVersion, policyId, null)).build();
+ }
+
+ /**
+ * Retrieves the specified version of a particular policy.
+ *
+ * @param policyTypeId the ID of specified policy type
+ * @param policyTypeVersion the version of specified policy type
+ * @param policyId the ID of specified policy
+ * @param policyVersion the version of specified policy
+ *
+ * @return the Response object containing the results of the API operation
+ */
+ @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 = ToscaPolicyList.class,
+ authorizations = @Authorization(value = "basicAuth"),
+ tags = { "Policy", })
+ @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 getSpecificVersionOfPolicy(
+ @PathParam("policyTypeId") @ApiParam("ID of policy type") String policyTypeId,
+ @PathParam("policyTypeVersion") @ApiParam("ID of policy type version") String policyTypeVersion,
+ @PathParam("policyId") @ApiParam("ID of policy") String policyId,
+ @PathParam("policyVersion") @ApiParam("ID of policy version") String policyVersion) {
+ return Response.status(Response.Status.OK)
+ .entity(new PolicyProvider().fetchPolicies(policyTypeId, policyTypeVersion,
+ policyId, policyVersion)).build();
+ }
+
+ /**
+ * Retrieves either latest or deployed version of a particular policy depending on query parameter.
+ *
+ * @param policyTypeId the ID of specified policy type
+ * @param policyTypeVersion the version of specified policy type
+ * @param policyId the ID of specified policy
+ *
+ * @return the Response object containing the results of the API operation
+ */
+ @GET
+ @Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}/versions")
+ @ApiOperation(value = "Retrieve either latest or deployed version of a particular policy depending on query param",
+ notes = "Returns either latest or deployed version of specified policy depending on query param",
+ response = ToscaPolicyList.class,
+ authorizations = @Authorization(value = "basicAuth"),
+ tags = { "Policy", })
+ @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 getEitherLatestOrDeployedVersionOfPolicy(
+ @PathParam("policyTypeId") @ApiParam("ID of policy type") String policyTypeId,
+ @PathParam("policyTypeVersion") @ApiParam("ID of policy type version") String policyTypeVersion,
+ @PathParam("policyId") @ApiParam("ID of policy") String policyId,
+ @QueryParam("type") @ApiParam("Type of version that can only be 'latest' or 'deployed'") String type) {
+ return Response.status(Response.Status.OK)
+ .entity(new PolicyProvider().fetchPolicies(policyTypeId, policyTypeVersion, policyId, type)).build();
+ }
+
+ /**
+ * Creates a new policy for a particular policy type and version.
+ *
+ * @param policyTypeId the ID of specified policy type
+ * @param policyTypeVersion the version of specified policy type
+ * @param body the body of policy following TOSCA definition
+ *
+ * @return the Response object containing the results of the API operation
+ */
+ @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", })
+ @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 createPolicy(
+ @PathParam("policyTypeId") @ApiParam("ID of policy type") String policyTypeId,
+ @PathParam("policyTypeVersion") @ApiParam("ID of policy type version") String policyTypeVersion,
+ ToscaPolicy body) {
+ return Response.status(Response.Status.OK)
+ .entity(new PolicyProvider().createPolicy(policyTypeId, policyTypeVersion, body)).build();
+ }
+
+ /**
+ * Deletes all versions of a particular policy.
+ *
+ * @param policyTypeId the ID of specified policy type
+ * @param policyTypeVersion the version of specified policy type
+ * @param policyId the ID of specified policy
+ *
+ * @return the Response object containing the results of the API operation
+ */
+ @DELETE
+ @Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}")
+ @ApiOperation(value = "Delete all versions of a policy",
+ notes = "Rule: the version that has been deployed in PDP group(s) cannot be deleted",
+ authorizations = @Authorization(value = "basicAuth"),
+ tags = { "Policy", })
+ @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 deleteAllVersionsOfPolicy(
+ @PathParam("policyTypeId") @ApiParam("ID of policy type") String policyTypeId,
+ @PathParam("policyTypeVersion") @ApiParam("ID of policy type version") String policyTypeVersion,
+ @PathParam("policyId") @ApiParam("ID of policy") String policyId) {
+ return Response.status(Response.Status.OK)
+ .entity(new PolicyProvider().deletePolicies(policyTypeId, policyTypeVersion, policyId, null)).build();
+ }
+
+ /**
+ * Deletes the specified version of a particular policy.
+ *
+ * @param policyTypeId the ID of specified policy type
+ * @param policyTypeVersion the version of specified policy type
+ * @param policyId the ID of specified policy
+ * @param policyVersion the version of specified policy
+ *
+ * @return the Response object containing the results of the API operation
+ */
+ @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", })
+ @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("PolicyType ID") String policyTypeId,
+ @PathParam("policyTypeVersion") @ApiParam("ID of policy type version") String policyTypeVersion,
+ @PathParam("policyId") @ApiParam("ID of policy") String policyId,
+ @PathParam("policyVersion") @ApiParam("ID of policy version") String policyVersion) {
+ return Response.status(Response.Status.OK)
+ .entity(new PolicyProvider().deletePolicies(policyTypeId, policyTypeVersion,
+ policyId, policyVersion)).build();
+ }