2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 * SPDX-License-Identifier: Apache-2.0
20 * ============LICENSE_END=========================================================
23 package org.onap.policy.api.main.rest;
25 import io.swagger.annotations.Api;
26 import io.swagger.annotations.ApiOperation;
27 import io.swagger.annotations.ApiParam;
28 import io.swagger.annotations.ApiResponse;
29 import io.swagger.annotations.ApiResponses;
30 import io.swagger.annotations.Authorization;
31 import io.swagger.annotations.Extension;
32 import io.swagger.annotations.ExtensionProperty;
33 import io.swagger.annotations.ResponseHeader;
34 import java.util.UUID;
35 import javax.ws.rs.Consumes;
36 import javax.ws.rs.DELETE;
37 import javax.ws.rs.GET;
38 import javax.ws.rs.HeaderParam;
39 import javax.ws.rs.POST;
40 import javax.ws.rs.Path;
41 import javax.ws.rs.PathParam;
42 import javax.ws.rs.Produces;
43 import javax.ws.rs.core.Response;
44 import javax.ws.rs.core.Response.ResponseBuilder;
45 import org.onap.policy.api.main.rest.provider.LegacyGuardPolicyProvider;
46 import org.onap.policy.api.main.rest.provider.LegacyOperationalPolicyProvider;
47 import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicy;
48 import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
49 import org.onap.policy.models.tosca.simple.concepts.ToscaServiceTemplate;
52 * Class to provide legacy REST API services.
54 * @author Chenfei Gao (cgao@research.att.com)
56 @Path("/policy/api/v1")
57 @Api(value = "Legacy Policy Design API")
58 @Produces({"application/json; vnd.onap.guard", "application/json; vnd.onap.operational"})
59 @Consumes({"application/json; vnd.onap.guard", "application/json; vnd.onap.operational"})
60 public class LegacyApiRestController {
63 * Retrieves all versions of guard policies.
65 * @return the Response object containing the results of the API operation
68 @Path("/policytypes/onap.policy.controlloop.guard/versions/1.0.0/policies")
69 @Produces("application/json; vnd.onap.guard")
70 @ApiOperation(value = "Retrieve all versions of guard policies",
71 notes = "Returns a list of all versions of guard policies",
72 response = ToscaServiceTemplate.class,
74 @ResponseHeader(name = "X-MinorVersion",
75 description = "Used to request or communicate a MINOR version back from the client"
76 + " to the server, and from the server back to the client",
77 response = String.class),
78 @ResponseHeader(name = "X-PatchVersion",
79 description = "Used only to communicate a PATCH version in a response for"
80 + " troubleshooting purposes only, and will not be provided by"
81 + " the client on request",
82 response = String.class),
83 @ResponseHeader(name = "X-LatestVersion",
84 description = "Used only to communicate an API's latest version",
85 response = String.class),
86 @ResponseHeader(name = "X-ONAP-RequestID",
87 description = "Used to track REST transactions for logging purpose",
88 response = UUID.class)
90 authorizations = @Authorization(value = "basicAuth"),
91 tags = { "Legacy Guard Policy", },
93 @Extension(name = "interface info", properties = {
94 @ExtensionProperty(name = "api-version", value = "1.0.0"),
95 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
98 @ApiResponses(value = {
99 @ApiResponse(code = 401, message = "Authentication Error"),
100 @ApiResponse(code = 403, message = "Authorization Error"),
101 @ApiResponse(code = 500, message = "Internal Server Error")
103 public Response getAllGuardPolicies(
104 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
105 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
106 .entity(new LegacyGuardPolicyProvider().fetchGuardPolicies(null, null)).build();
110 * Retrieves all versions of a particular guard policy.
112 * @param policyId the ID of specified guard policy
114 * @return the Response object containing the results of the API operation
117 @Path("/policytypes/onap.policy.controlloop.guard/versions/1.0.0/policies/{policyId}")
118 @Produces("application/json; vnd.onap.guard")
119 @ApiOperation(value = "Retrieve all versions of a particular guard policy",
120 notes = "Returns a list of all versions of the specified guard policy",
121 response = ToscaServiceTemplate.class,
123 @ResponseHeader(name = "X-MinorVersion",
124 description = "Used to request or communicate a MINOR version back from the client"
125 + " to the server, and from the server back to the client",
126 response = String.class),
127 @ResponseHeader(name = "X-PatchVersion",
128 description = "Used only to communicate a PATCH version in a response for"
129 + " troubleshooting purposes only, and will not be provided by"
130 + " the client on request",
131 response = String.class),
132 @ResponseHeader(name = "X-LatestVersion",
133 description = "Used only to communicate an API's latest version",
134 response = String.class),
135 @ResponseHeader(name = "X-ONAP-RequestID",
136 description = "Used to track REST transactions for logging purpose",
137 response = UUID.class)
139 authorizations = @Authorization(value = "basicAuth"),
140 tags = { "Legacy Guard Policy", },
142 @Extension(name = "interface info", properties = {
143 @ExtensionProperty(name = "api-version", value = "1.0.0"),
144 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
147 @ApiResponses(value = {
148 @ApiResponse(code = 401, message = "Authentication Error"),
149 @ApiResponse(code = 403, message = "Authorization Error"),
150 @ApiResponse(code = 404, message = "Resource Not Found"),
151 @ApiResponse(code = 500, message = "Internal Server Error")
153 public Response getAllVersionsOfGuardPolicy(
154 @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
155 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
156 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
157 .entity(new LegacyGuardPolicyProvider().fetchGuardPolicies(policyId, null)).build();
161 * Retrieves the specified version of a particular guard policy.
163 * @param policyId the ID of specified policy
164 * @param policyVersion the version of specified policy
166 * @return the Response object containing the results of the API operation
169 @Path("/policytypes/onap.policy.controlloop.guard/versions/1.0.0/policies/{policyId}/versions/{policyVersion}")
170 @Produces("application/json; vnd.onap.guard")
171 @ApiOperation(value = "Retrieve one version of a particular guard policy",
172 notes = "Returns a particular version of a specified guard policy",
173 response = ToscaServiceTemplate.class,
175 @ResponseHeader(name = "X-MinorVersion",
176 description = "Used to request or communicate a MINOR version back from the client"
177 + " to the server, and from the server back to the client",
178 response = String.class),
179 @ResponseHeader(name = "X-PatchVersion",
180 description = "Used only to communicate a PATCH version in a response for"
181 + " troubleshooting purposes only, and will not be provided by"
182 + " the client on request",
183 response = String.class),
184 @ResponseHeader(name = "X-LatestVersion",
185 description = "Used only to communicate an API's latest version",
186 response = String.class),
187 @ResponseHeader(name = "X-ONAP-RequestID",
188 description = "Used to track REST transactions for logging purpose",
189 response = UUID.class)
191 authorizations = @Authorization(value = "basicAuth"),
192 tags = { "Legacy Guard Policy", },
194 @Extension(name = "interface info", properties = {
195 @ExtensionProperty(name = "api-version", value = "1.0.0"),
196 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
199 @ApiResponses(value = {
200 @ApiResponse(code = 401, message = "Authentication Error"),
201 @ApiResponse(code = 403, message = "Authorization Error"),
202 @ApiResponse(code = 404, message = "Resource Not Found"),
203 @ApiResponse(code = 500, message = "Internal Server Error")
205 public Response getSpecificVersionOfGuardPolicy(
206 @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
207 @PathParam("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,
208 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
209 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
210 .entity(new LegacyGuardPolicyProvider().fetchGuardPolicies(policyId, policyVersion)).build();
214 * Creates a new guard policy.
216 * @param body the body of policy
218 * @return the Response object containing the results of the API operation
221 @Path("/policytypes/onap.policy.controlloop.guard/versions/1.0.0/policies")
222 @Consumes("application/json; vnd.onap.guard")
223 @Produces("application/json; vnd.onap.guard")
224 @ApiOperation(value = "Create a new guard policy",
225 notes = "Client should provide entity body of the new guard policy",
226 authorizations = @Authorization(value = "basicAuth"),
227 tags = { "Legacy Guard Policy", },
228 response = ToscaServiceTemplate.class,
230 @ResponseHeader(name = "X-MinorVersion",
231 description = "Used to request or communicate a MINOR version back from the client"
232 + " to the server, and from the server back to the client",
233 response = String.class),
234 @ResponseHeader(name = "X-PatchVersion",
235 description = "Used only to communicate a PATCH version in a response for"
236 + " troubleshooting purposes only, and will not be provided by"
237 + " the client on request",
238 response = String.class),
239 @ResponseHeader(name = "X-LatestVersion",
240 description = "Used only to communicate an API's latest version",
241 response = String.class),
242 @ResponseHeader(name = "X-ONAP-RequestID",
243 description = "Used to track REST transactions for logging purpose",
244 response = UUID.class)
247 @Extension(name = "interface info", properties = {
248 @ExtensionProperty(name = "api-version", value = "1.0.0"),
249 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
252 @ApiResponses(value = {
253 @ApiResponse(code = 400, message = "Invalid Body"),
254 @ApiResponse(code = 401, message = "Authentication Error"),
255 @ApiResponse(code = 403, message = "Authorization Error"),
256 @ApiResponse(code = 500, message = "Internal Server Error")
258 public Response createGuardPolicy(
259 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId,
260 @ApiParam(value = "Entity body of policy", required = true) LegacyGuardPolicy body) {
261 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
262 .entity(new LegacyGuardPolicyProvider().createGuardPolicy(body)).build();
266 * Deletes all versions of a particular guard policy.
268 * @param policyId the ID of specified policy
270 * @return the Response object containing the results of the API operation
273 @Path("/policytypes/onap.policy.controlloop.guard/versions/1.0.0/policies/{policyId}")
274 @ApiOperation(value = "Delete all versions of a guard policy",
275 notes = "Rule: the version that has been deployed in PDP group(s) cannot be deleted",
276 authorizations = @Authorization(value = "basicAuth"),
277 tags = { "Legacy Guard Policy", },
279 @Extension(name = "interface info", properties = {
280 @ExtensionProperty(name = "api-version", value = "1.0.0"),
281 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
284 @ApiResponses(value = {
285 @ApiResponse(code = 204, message = "Resources successfully deleted, no content returned",
287 @ResponseHeader(name = "X-MinorVersion",
288 description = "Used to request or communicate a MINOR version back from the client"
289 + " to the server, and from the server back to the client",
290 response = String.class),
291 @ResponseHeader(name = "X-PatchVersion",
292 description = "Used only to communicate a PATCH version in a response for"
293 + " troubleshooting purposes only, and will not be provided by"
294 + " the client on request",
295 response = String.class),
296 @ResponseHeader(name = "X-LatestVersion",
297 description = "Used only to communicate an API's latest version",
298 response = String.class),
299 @ResponseHeader(name = "X-ONAP-RequestID",
300 description = "Used to track REST transactions for logging purpose",
301 response = UUID.class)
303 @ApiResponse(code = 401, message = "Authentication Error"),
304 @ApiResponse(code = 403, message = "Authorization Error"),
305 @ApiResponse(code = 404, message = "Resource Not Found"),
306 @ApiResponse(code = 409, message = "Delete Conflict, Rule Violation"),
307 @ApiResponse(code = 500, message = "Internal Server Error")
309 public Response deleteAllVersionsOfGuardPolicy(
310 @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
311 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
312 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
313 .entity(new LegacyGuardPolicyProvider().deleteGuardPolicies(policyId, null)).build();
317 * Deletes the specified version of a particular guard policy.
319 * @param policyId the ID of specified policy
320 * @param policyVersion the version of specified policy
322 * @return the Response object containing the results of the API operation
325 @Path("/policytypes/onap.policy.controlloop.guard/versions/1.0.0/policies/{policyId}/versions/{policyVersion}")
326 @ApiOperation(value = "Delete a particular version of a guard policy",
327 notes = "Rule: the version that has been deployed in PDP group(s) cannot be deleted",
328 authorizations = @Authorization(value = "basicAuth"),
329 tags = { "Legacy Guard Policy", },
331 @Extension(name = "interface info", properties = {
332 @ExtensionProperty(name = "api-version", value = "1.0.0"),
333 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
336 @ApiResponses(value = {
337 @ApiResponse(code = 204, message = "Resource successfully deleted, no content returned",
339 @ResponseHeader(name = "X-MinorVersion",
340 description = "Used to request or communicate a MINOR version back from the client"
341 + " to the server, and from the server back to the client",
342 response = String.class),
343 @ResponseHeader(name = "X-PatchVersion",
344 description = "Used only to communicate a PATCH version in a response for"
345 + " troubleshooting purposes only, and will not be provided by"
346 + " the client on request",
347 response = String.class),
348 @ResponseHeader(name = "X-LatestVersion",
349 description = "Used only to communicate an API's latest version",
350 response = String.class),
351 @ResponseHeader(name = "X-ONAP-RequestID",
352 description = "Used to track REST transactions for logging purpose",
353 response = UUID.class)
355 @ApiResponse(code = 401, message = "Authentication Error"),
356 @ApiResponse(code = 403, message = "Authorization Error"),
357 @ApiResponse(code = 404, message = "Resource Not Found"),
358 @ApiResponse(code = 409, message = "Delete Conflict, Rule Violation"),
359 @ApiResponse(code = 500, message = "Internal Server Error")
361 public Response deleteSpecificVersionOfGuardPolicy(
362 @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
363 @PathParam("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,
364 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
365 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
366 .entity(new LegacyGuardPolicyProvider().deleteGuardPolicies(policyId, policyVersion)).build();
370 * Retrieves all versions of operational policies.
372 * @return the Response object containing the results of the API operation
375 @Path("/policytypes/onap.policy.controlloop.operational/versions/1.0.0/policies")
376 @Produces("application/json; vnd.onap.operational")
377 @ApiOperation(value = "Retrieve all versions of operational policies",
378 notes = "Returns a list of all versions of operational policies",
379 response = ToscaServiceTemplate.class,
381 @ResponseHeader(name = "X-MinorVersion",
382 description = "Used to request or communicate a MINOR version back from the client"
383 + " to the server, and from the server back to the client",
384 response = String.class),
385 @ResponseHeader(name = "X-PatchVersion",
386 description = "Used only to communicate a PATCH version in a response for"
387 + " troubleshooting purposes only, and will not be provided by"
388 + " the client on request",
389 response = String.class),
390 @ResponseHeader(name = "X-LatestVersion",
391 description = "Used only to communicate an API's latest version",
392 response = String.class),
393 @ResponseHeader(name = "X-ONAP-RequestID",
394 description = "Used to track REST transactions for logging purpose",
395 response = UUID.class)
397 authorizations = @Authorization(value = "basicAuth"),
398 tags = { "Legacy Operational Policy", },
400 @Extension(name = "interface info", properties = {
401 @ExtensionProperty(name = "api-version", value = "1.0.0"),
402 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
405 @ApiResponses(value = {
406 @ApiResponse(code = 401, message = "Authentication Error"),
407 @ApiResponse(code = 403, message = "Authorization Error"),
408 @ApiResponse(code = 500, message = "Internal Server Error")
410 public Response getAllOperationalPolicies(
411 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
412 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
413 .entity(new LegacyOperationalPolicyProvider().fetchOperationalPolicies(null, null)).build();
417 * Retrieves all versions of a particular operational policy.
419 * @param policyId the ID of specified operational policy
421 * @return the Response object containing the results of the API operation
424 @Path("/policytypes/onap.policy.controlloop.operational/versions/1.0.0/policies/{policyId}")
425 @Produces("application/json; vnd.onap.operational")
426 @ApiOperation(value = "Retrieve all versions of a particular operational policy",
427 notes = "Returns a list of all versions of the specified operational policy",
428 response = ToscaServiceTemplate.class,
430 @ResponseHeader(name = "X-MinorVersion",
431 description = "Used to request or communicate a MINOR version back from the client"
432 + " to the server, and from the server back to the client",
433 response = String.class),
434 @ResponseHeader(name = "X-PatchVersion",
435 description = "Used only to communicate a PATCH version in a response for"
436 + " troubleshooting purposes only, and will not be provided by"
437 + " the client on request",
438 response = String.class),
439 @ResponseHeader(name = "X-LatestVersion",
440 description = "Used only to communicate an API's latest version",
441 response = String.class),
442 @ResponseHeader(name = "X-ONAP-RequestID",
443 description = "Used to track REST transactions for logging purpose",
444 response = UUID.class)
446 authorizations = @Authorization(value = "basicAuth"),
447 tags = { "Legacy Operational Policy", },
449 @Extension(name = "interface info", properties = {
450 @ExtensionProperty(name = "api-version", value = "1.0.0"),
451 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
454 @ApiResponses(value = {
455 @ApiResponse(code = 401, message = "Authentication Error"),
456 @ApiResponse(code = 403, message = "Authorization Error"),
457 @ApiResponse(code = 404, message = "Resource Not Found"),
458 @ApiResponse(code = 500, message = "Internal Server Error")
460 public Response getAllVersionsOfOperationalPolicy(
461 @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
462 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
463 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
464 .entity(new LegacyOperationalPolicyProvider().fetchOperationalPolicies(policyId, null)).build();
468 * Retrieves the specified version of a particular operational policy.
470 * @param policyId the ID of specified policy
471 * @param policyVersion the version of specified policy
473 * @return the Response object containing the results of the API operation
476 @Path("/policytypes/onap.policy.controlloop.operational/versions/1.0.0/"
477 + "policies/{policyId}/versions/{policyVersion}")
478 @Produces("application/json; vnd.onap.operational")
479 @ApiOperation(value = "Retrieve one version of a particular operational policy",
480 notes = "Returns a particular version of a specified operational policy",
481 response = ToscaServiceTemplate.class,
483 @ResponseHeader(name = "X-MinorVersion",
484 description = "Used to request or communicate a MINOR version back from the client"
485 + " to the server, and from the server back to the client",
486 response = String.class),
487 @ResponseHeader(name = "X-PatchVersion",
488 description = "Used only to communicate a PATCH version in a response for"
489 + " troubleshooting purposes only, and will not be provided by"
490 + " the client on request",
491 response = String.class),
492 @ResponseHeader(name = "X-LatestVersion",
493 description = "Used only to communicate an API's latest version",
494 response = String.class),
495 @ResponseHeader(name = "X-ONAP-RequestID",
496 description = "Used to track REST transactions for logging purpose",
497 response = UUID.class)
499 authorizations = @Authorization(value = "basicAuth"),
500 tags = { "Legacy Operational Policy", },
502 @Extension(name = "interface info", properties = {
503 @ExtensionProperty(name = "api-version", value = "1.0.0"),
504 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
507 @ApiResponses(value = {
508 @ApiResponse(code = 401, message = "Authentication Error"),
509 @ApiResponse(code = 403, message = "Authorization Error"),
510 @ApiResponse(code = 404, message = "Resource Not Found"),
511 @ApiResponse(code = 500, message = "Internal Server Error")
513 public Response getSpecificVersionOfOperationalPolicy(
514 @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
515 @PathParam("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,
516 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
517 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
518 .entity(new LegacyOperationalPolicyProvider().fetchOperationalPolicies(policyId, policyVersion)).build();
522 * Creates a new operational policy.
524 * @param body the body of policy
526 * @return the Response object containing the results of the API operation
529 @Path("/policytypes/onap.policy.controlloop.operational/versions/1.0.0/policies")
530 @Consumes("application/json; vnd.onap.operational")
531 @Produces("application/json; vnd.onap.operational")
532 @ApiOperation(value = "Create a new operational policy",
533 notes = "Client should provide entity body of the new operational policy",
534 authorizations = @Authorization(value = "basicAuth"),
535 tags = { "Legacy Operational Policy", },
536 response = ToscaServiceTemplate.class,
538 @ResponseHeader(name = "X-MinorVersion",
539 description = "Used to request or communicate a MINOR version back from the client"
540 + " to the server, and from the server back to the client",
541 response = String.class),
542 @ResponseHeader(name = "X-PatchVersion",
543 description = "Used only to communicate a PATCH version in a response for"
544 + " troubleshooting purposes only, and will not be provided by"
545 + " the client on request",
546 response = String.class),
547 @ResponseHeader(name = "X-LatestVersion",
548 description = "Used only to communicate an API's latest version",
549 response = String.class),
550 @ResponseHeader(name = "X-ONAP-RequestID",
551 description = "Used to track REST transactions for logging purpose",
552 response = UUID.class)
555 @Extension(name = "interface info", properties = {
556 @ExtensionProperty(name = "api-version", value = "1.0.0"),
557 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
560 @ApiResponses(value = {
561 @ApiResponse(code = 400, message = "Invalid Body"),
562 @ApiResponse(code = 401, message = "Authentication Error"),
563 @ApiResponse(code = 403, message = "Authorization Error"),
564 @ApiResponse(code = 500, message = "Internal Server Error")
566 public Response createOperationalPolicy(
567 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId,
568 @ApiParam(value = "Entity body of policy", required = true) LegacyOperationalPolicy body) {
569 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
570 .entity(new LegacyOperationalPolicyProvider().createOperationalPolicy(body)).build();
574 * Deletes all versions of a particular operational policy.
576 * @param policyId the ID of specified policy
578 * @return the Response object containing the results of the API operation
581 @Path("/policytypes/onap.policy.controlloop.operational/versions/1.0.0/policies/{policyId}")
582 @ApiOperation(value = "Delete all versions of a operational policy",
583 notes = "Rule: the version that has been deployed in PDP group(s) cannot be deleted",
584 authorizations = @Authorization(value = "basicAuth"),
585 tags = { "Legacy Operational Policy", },
587 @Extension(name = "interface info", properties = {
588 @ExtensionProperty(name = "api-version", value = "1.0.0"),
589 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
592 @ApiResponses(value = {
593 @ApiResponse(code = 204, message = "Resources successfully deleted, no content returned",
595 @ResponseHeader(name = "X-MinorVersion",
596 description = "Used to request or communicate a MINOR version back from the client"
597 + " to the server, and from the server back to the client",
598 response = String.class),
599 @ResponseHeader(name = "X-PatchVersion",
600 description = "Used only to communicate a PATCH version in a response for"
601 + " troubleshooting purposes only, and will not be provided by"
602 + " the client on request",
603 response = String.class),
604 @ResponseHeader(name = "X-LatestVersion",
605 description = "Used only to communicate an API's latest version",
606 response = String.class),
607 @ResponseHeader(name = "X-ONAP-RequestID",
608 description = "Used to track REST transactions for logging purpose",
609 response = UUID.class)
611 @ApiResponse(code = 401, message = "Authentication Error"),
612 @ApiResponse(code = 403, message = "Authorization Error"),
613 @ApiResponse(code = 404, message = "Resource Not Found"),
614 @ApiResponse(code = 409, message = "Delete Conflict, Rule Violation"),
615 @ApiResponse(code = 500, message = "Internal Server Error")
617 public Response deleteAllVersionsOfOperationalPolicy(
618 @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
619 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
620 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
621 .entity(new LegacyOperationalPolicyProvider().deleteOperationalPolicies(policyId, null)).build();
625 * Deletes the specified version of a particular operational policy.
627 * @param policyId the ID of specified policy
628 * @param policyVersion the version of specified policy
630 * @return the Response object containing the results of the API operation
633 @Path("/policytypes/onap.policy.controlloop.operational/versions/1.0.0/"
634 + "policies/{policyId}/versions/{policyVersion}")
635 @ApiOperation(value = "Delete a particular version of a specified operational policy",
636 notes = "Rule: the version that has been deployed in PDP group(s) cannot be deleted",
637 authorizations = @Authorization(value = "basicAuth"),
638 tags = { "Legacy Operational Policy", },
640 @Extension(name = "interface info", properties = {
641 @ExtensionProperty(name = "api-version", value = "1.0.0"),
642 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
645 @ApiResponses(value = {
646 @ApiResponse(code = 204, message = "Resource successfully deleted, no content returned",
648 @ResponseHeader(name = "X-MinorVersion",
649 description = "Used to request or communicate a MINOR version back from the client"
650 + " to the server, and from the server back to the client",
651 response = String.class),
652 @ResponseHeader(name = "X-PatchVersion",
653 description = "Used only to communicate a PATCH version in a response for"
654 + " troubleshooting purposes only, and will not be provided by"
655 + " the client on request",
656 response = String.class),
657 @ResponseHeader(name = "X-LatestVersion",
658 description = "Used only to communicate an API's latest version",
659 response = String.class),
660 @ResponseHeader(name = "X-ONAP-RequestID",
661 description = "Used to track REST transactions for logging purpose",
662 response = UUID.class)
664 @ApiResponse(code = 401, message = "Authentication Error"),
665 @ApiResponse(code = 403, message = "Authorization Error"),
666 @ApiResponse(code = 404, message = "Resource Not Found"),
667 @ApiResponse(code = 409, message = "Delete Conflict, Rule Violation"),
668 @ApiResponse(code = 500, message = "Internal Server Error")
670 public Response deleteSpecificVersionOfOperationalPolicy(
671 @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
672 @PathParam("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,
673 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
674 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
675 .entity(new LegacyOperationalPolicyProvider().deleteOperationalPolicies(policyId, policyVersion)).build();
678 private ResponseBuilder addVersionControlHeaders(ResponseBuilder rb) {
679 return rb.header("X-MinorVersion", "0").header("X-PatchVersion", "0").header("X-LatestVersion", "1.0.0");
682 private ResponseBuilder addLoggingHeaders(ResponseBuilder rb, UUID requestId) {
683 if (requestId == null) {
684 // Generate a random uuid if client does not embed requestId in rest request
685 return rb.header("X-ONAP-RequestID", UUID.randomUUID());
687 return rb.header("X-ONAP-RequestID", requestId);