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;
35 import java.util.UUID;
36 import javax.ws.rs.Consumes;
37 import javax.ws.rs.DELETE;
38 import javax.ws.rs.GET;
39 import javax.ws.rs.HeaderParam;
40 import javax.ws.rs.POST;
41 import javax.ws.rs.Path;
42 import javax.ws.rs.PathParam;
43 import javax.ws.rs.Produces;
44 import javax.ws.rs.core.Response;
45 import javax.ws.rs.core.Response.ResponseBuilder;
46 import org.onap.policy.api.main.rest.provider.LegacyGuardPolicyProvider;
47 import org.onap.policy.api.main.rest.provider.LegacyOperationalPolicyProvider;
48 import org.onap.policy.models.base.PfModelException;
49 import org.onap.policy.models.base.PfModelRuntimeException;
50 import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyInput;
51 import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyOutput;
52 import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
53 import org.slf4j.Logger;
54 import org.slf4j.LoggerFactory;
57 * Class to provide legacy REST API services.
59 * @author Chenfei Gao (cgao@research.att.com)
61 @Path("/policy/api/v1")
62 @Api(value = "Legacy Policy Design API")
63 @Produces("application/json")
64 @Consumes("application/json")
65 public class LegacyApiRestController {
67 private static final Logger LOGGER = LoggerFactory.getLogger(LegacyApiRestController.class);
70 * Retrieves the latest version of a particular guard policy.
72 * @param policyId the ID of specified guard policy
74 * @return the Response object containing the results of the API operation
77 @Path("/policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/{policyId}/versions/latest")
78 @ApiOperation(value = "Retrieve the latest version of a particular guard policy",
79 notes = "Returns the latest version of the specified guard policy",
80 response = LegacyGuardPolicyOutput.class, responseContainer = "Map",
82 @ResponseHeader(name = "X-MinorVersion",
83 description = "Used to request or communicate a MINOR version back from the client"
84 + " to the server, and from the server back to the client",
85 response = String.class),
86 @ResponseHeader(name = "X-PatchVersion",
87 description = "Used only to communicate a PATCH version in a response for"
88 + " troubleshooting purposes only, and will not be provided by"
89 + " the client on request",
90 response = String.class),
91 @ResponseHeader(name = "X-LatestVersion",
92 description = "Used only to communicate an API's latest version",
93 response = String.class),
94 @ResponseHeader(name = "X-ONAP-RequestID",
95 description = "Used to track REST transactions for logging purpose",
96 response = UUID.class)
98 authorizations = @Authorization(value = "basicAuth"),
99 tags = { "Legacy Guard Policy", },
101 @Extension(name = "interface info", properties = {
102 @ExtensionProperty(name = "api-version", value = "1.0.0"),
103 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
106 @ApiResponses(value = {
107 @ApiResponse(code = 401, message = "Authentication Error"),
108 @ApiResponse(code = 403, message = "Authorization Error"),
109 @ApiResponse(code = 404, message = "Resource Not Found"),
110 @ApiResponse(code = 500, message = "Internal Server Error")
112 public Response getLatestVersionOfGuardPolicy(
113 @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
114 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
116 try (LegacyGuardPolicyProvider guardPolicyProvider = new LegacyGuardPolicyProvider()) {
117 Map<String, LegacyGuardPolicyOutput> policies = guardPolicyProvider.fetchGuardPolicy(policyId, null);
118 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
119 .entity(policies).build();
120 } catch (PfModelException | PfModelRuntimeException pfme) {
121 LOGGER.error("GET /policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/{}"
122 + "/versions/latest", policyId, pfme);
123 return addLoggingHeaders(addVersionControlHeaders(
124 Response.status(pfme.getErrorResponse().getResponseCode())), requestId)
125 .entity(pfme.getErrorResponse()).build();
130 * Retrieves the specified version of a particular guard policy.
132 * @param policyId the ID of specified policy
133 * @param policyVersion the version of specified policy
135 * @return the Response object containing the results of the API operation
138 @Path("/policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/{policyId}/versions/{policyVersion}")
139 @ApiOperation(value = "Retrieve one version of a particular guard policy",
140 notes = "Returns a particular version of a specified guard policy",
141 response = LegacyGuardPolicyOutput.class, responseContainer = "Map",
143 @ResponseHeader(name = "X-MinorVersion",
144 description = "Used to request or communicate a MINOR version back from the client"
145 + " to the server, and from the server back to the client",
146 response = String.class),
147 @ResponseHeader(name = "X-PatchVersion",
148 description = "Used only to communicate a PATCH version in a response for"
149 + " troubleshooting purposes only, and will not be provided by"
150 + " the client on request",
151 response = String.class),
152 @ResponseHeader(name = "X-LatestVersion",
153 description = "Used only to communicate an API's latest version",
154 response = String.class),
155 @ResponseHeader(name = "X-ONAP-RequestID",
156 description = "Used to track REST transactions for logging purpose",
157 response = UUID.class)
159 authorizations = @Authorization(value = "basicAuth"),
160 tags = { "Legacy Guard Policy", },
162 @Extension(name = "interface info", properties = {
163 @ExtensionProperty(name = "api-version", value = "1.0.0"),
164 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
167 @ApiResponses(value = {
168 @ApiResponse(code = 401, message = "Authentication Error"),
169 @ApiResponse(code = 403, message = "Authorization Error"),
170 @ApiResponse(code = 404, message = "Resource Not Found"),
171 @ApiResponse(code = 500, message = "Internal Server Error")
173 public Response getSpecificVersionOfGuardPolicy(
174 @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
175 @PathParam("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,
176 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
178 try (LegacyGuardPolicyProvider guardPolicyProvider = new LegacyGuardPolicyProvider()) {
179 Map<String, LegacyGuardPolicyOutput> policies = guardPolicyProvider
180 .fetchGuardPolicy(policyId, policyVersion);
181 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
182 .entity(policies).build();
183 } catch (PfModelException | PfModelRuntimeException pfme) {
184 LOGGER.error("GET /policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/{}/versions/{}",
185 policyId, policyVersion, pfme);
186 return addLoggingHeaders(addVersionControlHeaders(
187 Response.status(pfme.getErrorResponse().getResponseCode())), requestId)
188 .entity(pfme.getErrorResponse()).build();
193 * Creates a new guard policy.
195 * @param body the body of policy
197 * @return the Response object containing the results of the API operation
200 @Path("/policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies")
201 @ApiOperation(value = "Create a new guard policy",
202 notes = "Client should provide entity body of the new guard policy",
203 authorizations = @Authorization(value = "basicAuth"),
204 tags = { "Legacy Guard Policy", },
205 response = LegacyGuardPolicyOutput.class, responseContainer = "Map",
207 @ResponseHeader(name = "X-MinorVersion",
208 description = "Used to request or communicate a MINOR version back from the client"
209 + " to the server, and from the server back to the client",
210 response = String.class),
211 @ResponseHeader(name = "X-PatchVersion",
212 description = "Used only to communicate a PATCH version in a response for"
213 + " troubleshooting purposes only, and will not be provided by"
214 + " the client on request",
215 response = String.class),
216 @ResponseHeader(name = "X-LatestVersion",
217 description = "Used only to communicate an API's latest version",
218 response = String.class),
219 @ResponseHeader(name = "X-ONAP-RequestID",
220 description = "Used to track REST transactions for logging purpose",
221 response = UUID.class)
224 @Extension(name = "interface info", properties = {
225 @ExtensionProperty(name = "api-version", value = "1.0.0"),
226 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
229 @ApiResponses(value = {
230 @ApiResponse(code = 400, message = "Invalid Body"),
231 @ApiResponse(code = 401, message = "Authentication Error"),
232 @ApiResponse(code = 403, message = "Authorization Error"),
233 @ApiResponse(code = 500, message = "Internal Server Error")
235 public Response createGuardPolicy(
236 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId,
237 @ApiParam(value = "Entity body of policy", required = true) LegacyGuardPolicyInput body) {
239 try (LegacyGuardPolicyProvider guardPolicyProvider = new LegacyGuardPolicyProvider()) {
240 Map<String, LegacyGuardPolicyOutput> policy = guardPolicyProvider.createGuardPolicy(body);
241 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
242 .entity(policy).build();
243 } catch (PfModelException | PfModelRuntimeException pfme) {
244 LOGGER.error("POST /policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies", pfme);
245 return addLoggingHeaders(addVersionControlHeaders(
246 Response.status(pfme.getErrorResponse().getResponseCode())), requestId)
247 .entity(pfme.getErrorResponse()).build();
252 * Deletes the specified version of a particular guard policy.
254 * @param policyId the ID of specified policy
255 * @param policyVersion the version of specified policy
257 * @return the Response object containing the results of the API operation
260 @Path("/policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/{policyId}/versions/{policyVersion}")
261 @ApiOperation(value = "Delete a particular version of a guard policy",
262 notes = "Rule: the version that has been deployed in PDP group(s) cannot be deleted",
263 authorizations = @Authorization(value = "basicAuth"),
264 tags = { "Legacy Guard Policy", },
265 response = LegacyGuardPolicyOutput.class, responseContainer = "Map",
267 @ResponseHeader(name = "X-MinorVersion",
268 description = "Used to request or communicate a MINOR version back from the client"
269 + " to the server, and from the server back to the client",
270 response = String.class),
271 @ResponseHeader(name = "X-PatchVersion",
272 description = "Used only to communicate a PATCH version in a response for"
273 + " troubleshooting purposes only, and will not be provided by"
274 + " the client on request",
275 response = String.class),
276 @ResponseHeader(name = "X-LatestVersion",
277 description = "Used only to communicate an API's latest version",
278 response = String.class),
279 @ResponseHeader(name = "X-ONAP-RequestID",
280 description = "Used to track REST transactions for logging purpose",
281 response = UUID.class)
284 @Extension(name = "interface info", properties = {
285 @ExtensionProperty(name = "api-version", value = "1.0.0"),
286 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
289 @ApiResponses(value = {
290 @ApiResponse(code = 401, message = "Authentication Error"),
291 @ApiResponse(code = 403, message = "Authorization Error"),
292 @ApiResponse(code = 404, message = "Resource Not Found"),
293 @ApiResponse(code = 409, message = "Delete Conflict, Rule Violation"),
294 @ApiResponse(code = 500, message = "Internal Server Error")
296 public Response deleteSpecificVersionOfGuardPolicy(
297 @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
298 @PathParam("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,
299 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
301 try (LegacyGuardPolicyProvider guardPolicyProvider = new LegacyGuardPolicyProvider()) {
302 Map<String, LegacyGuardPolicyOutput> policies = guardPolicyProvider
303 .deleteGuardPolicy(policyId, policyVersion);
304 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
305 .entity(policies).build();
306 } catch (PfModelException | PfModelRuntimeException pfme) {
307 LOGGER.error("DELETE /policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/{}/versions/{}",
308 policyId, policyVersion, pfme);
309 return addLoggingHeaders(addVersionControlHeaders(
310 Response.status(pfme.getErrorResponse().getResponseCode())), requestId)
311 .entity(pfme.getErrorResponse()).build();
316 * Retrieves the latest version of a particular operational policy.
318 * @param policyId the ID of specified operational policy
320 * @return the Response object containing the results of the API operation
323 @Path("/policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies/{policyId}/versions/latest")
324 @ApiOperation(value = "Retrieve the latest version of a particular operational policy",
325 notes = "Returns the latest version of the specified operational policy",
326 response = LegacyOperationalPolicy.class,
328 @ResponseHeader(name = "X-MinorVersion",
329 description = "Used to request or communicate a MINOR version back from the client"
330 + " to the server, and from the server back to the client",
331 response = String.class),
332 @ResponseHeader(name = "X-PatchVersion",
333 description = "Used only to communicate a PATCH version in a response for"
334 + " troubleshooting purposes only, and will not be provided by"
335 + " the client on request",
336 response = String.class),
337 @ResponseHeader(name = "X-LatestVersion",
338 description = "Used only to communicate an API's latest version",
339 response = String.class),
340 @ResponseHeader(name = "X-ONAP-RequestID",
341 description = "Used to track REST transactions for logging purpose",
342 response = UUID.class)
344 authorizations = @Authorization(value = "basicAuth"),
345 tags = { "Legacy Operational Policy", },
347 @Extension(name = "interface info", properties = {
348 @ExtensionProperty(name = "api-version", value = "1.0.0"),
349 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
352 @ApiResponses(value = {
353 @ApiResponse(code = 401, message = "Authentication Error"),
354 @ApiResponse(code = 403, message = "Authorization Error"),
355 @ApiResponse(code = 404, message = "Resource Not Found"),
356 @ApiResponse(code = 500, message = "Internal Server Error")
358 public Response getLatestVersionOfOperationalPolicy(
359 @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
360 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
362 try (LegacyOperationalPolicyProvider operationalPolicyProvider = new LegacyOperationalPolicyProvider()) {
363 LegacyOperationalPolicy policy = operationalPolicyProvider.fetchOperationalPolicy(policyId, null);
364 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
365 .entity(policy).build();
366 } catch (PfModelException | PfModelRuntimeException pfme) {
367 LOGGER.error("GET /policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies/{}"
368 + "/versions/latest", policyId, pfme);
369 return addLoggingHeaders(addVersionControlHeaders(
370 Response.status(pfme.getErrorResponse().getResponseCode())), requestId)
371 .entity(pfme.getErrorResponse()).build();
376 * Retrieves the specified version of a particular operational policy.
378 * @param policyId the ID of specified policy
379 * @param policyVersion the version of specified policy
381 * @return the Response object containing the results of the API operation
384 @Path("/policytypes/onap.policies.controlloop.Operational/versions/1.0.0/"
385 + "policies/{policyId}/versions/{policyVersion}")
386 @ApiOperation(value = "Retrieve one version of a particular operational policy",
387 notes = "Returns a particular version of a specified operational policy",
388 response = LegacyOperationalPolicy.class,
390 @ResponseHeader(name = "X-MinorVersion",
391 description = "Used to request or communicate a MINOR version back from the client"
392 + " to the server, and from the server back to the client",
393 response = String.class),
394 @ResponseHeader(name = "X-PatchVersion",
395 description = "Used only to communicate a PATCH version in a response for"
396 + " troubleshooting purposes only, and will not be provided by"
397 + " the client on request",
398 response = String.class),
399 @ResponseHeader(name = "X-LatestVersion",
400 description = "Used only to communicate an API's latest version",
401 response = String.class),
402 @ResponseHeader(name = "X-ONAP-RequestID",
403 description = "Used to track REST transactions for logging purpose",
404 response = UUID.class)
406 authorizations = @Authorization(value = "basicAuth"),
407 tags = { "Legacy Operational Policy", },
409 @Extension(name = "interface info", properties = {
410 @ExtensionProperty(name = "api-version", value = "1.0.0"),
411 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
414 @ApiResponses(value = {
415 @ApiResponse(code = 401, message = "Authentication Error"),
416 @ApiResponse(code = 403, message = "Authorization Error"),
417 @ApiResponse(code = 404, message = "Resource Not Found"),
418 @ApiResponse(code = 500, message = "Internal Server Error")
420 public Response getSpecificVersionOfOperationalPolicy(
421 @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
422 @PathParam("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,
423 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
425 try (LegacyOperationalPolicyProvider operationalPolicyProvider = new LegacyOperationalPolicyProvider()) {
426 LegacyOperationalPolicy policy = operationalPolicyProvider.fetchOperationalPolicy(policyId, policyVersion);
427 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
428 .entity(policy).build();
429 } catch (PfModelException | PfModelRuntimeException pfme) {
430 LOGGER.error("GET /policytypes/onap.policies.controlloop.Operational/versions/1.0.0/"
431 + "policies/{}/versions/{}", policyId, policyVersion, pfme);
432 return addLoggingHeaders(addVersionControlHeaders(
433 Response.status(pfme.getErrorResponse().getResponseCode())), requestId)
434 .entity(pfme.getErrorResponse()).build();
439 * Creates a new operational policy.
441 * @param body the body of policy
443 * @return the Response object containing the results of the API operation
446 @Path("/policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies")
447 @ApiOperation(value = "Create a new operational policy",
448 notes = "Client should provide entity body of the new operational policy",
449 authorizations = @Authorization(value = "basicAuth"),
450 tags = { "Legacy Operational Policy", },
451 response = LegacyOperationalPolicy.class,
453 @ResponseHeader(name = "X-MinorVersion",
454 description = "Used to request or communicate a MINOR version back from the client"
455 + " to the server, and from the server back to the client",
456 response = String.class),
457 @ResponseHeader(name = "X-PatchVersion",
458 description = "Used only to communicate a PATCH version in a response for"
459 + " troubleshooting purposes only, and will not be provided by"
460 + " the client on request",
461 response = String.class),
462 @ResponseHeader(name = "X-LatestVersion",
463 description = "Used only to communicate an API's latest version",
464 response = String.class),
465 @ResponseHeader(name = "X-ONAP-RequestID",
466 description = "Used to track REST transactions for logging purpose",
467 response = UUID.class)
470 @Extension(name = "interface info", properties = {
471 @ExtensionProperty(name = "api-version", value = "1.0.0"),
472 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
475 @ApiResponses(value = {
476 @ApiResponse(code = 400, message = "Invalid Body"),
477 @ApiResponse(code = 401, message = "Authentication Error"),
478 @ApiResponse(code = 403, message = "Authorization Error"),
479 @ApiResponse(code = 500, message = "Internal Server Error")
481 public Response createOperationalPolicy(
482 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId,
483 @ApiParam(value = "Entity body of policy", required = true) LegacyOperationalPolicy body) {
485 try (LegacyOperationalPolicyProvider operationalPolicyProvider = new LegacyOperationalPolicyProvider()) {
486 LegacyOperationalPolicy policy = operationalPolicyProvider.createOperationalPolicy(body);
487 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
488 .entity(policy).build();
489 } catch (PfModelException | PfModelRuntimeException pfme) {
490 LOGGER.error("POST /policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies", pfme);
491 return addLoggingHeaders(addVersionControlHeaders(
492 Response.status(pfme.getErrorResponse().getResponseCode())), requestId)
493 .entity(pfme.getErrorResponse()).build();
498 * Deletes the specified version of a particular operational policy.
500 * @param policyId the ID of specified policy
501 * @param policyVersion the version of specified policy
503 * @return the Response object containing the results of the API operation
506 @Path("/policytypes/onap.policies.controlloop.Operational/versions/1.0.0/"
507 + "policies/{policyId}/versions/{policyVersion}")
508 @ApiOperation(value = "Delete a particular version of a specified operational policy",
509 notes = "Rule: the version that has been deployed in PDP group(s) cannot be deleted",
510 authorizations = @Authorization(value = "basicAuth"),
511 tags = { "Legacy Operational Policy", },
512 response = LegacyOperationalPolicy.class,
514 @ResponseHeader(name = "X-MinorVersion",
515 description = "Used to request or communicate a MINOR version back from the client"
516 + " to the server, and from the server back to the client",
517 response = String.class),
518 @ResponseHeader(name = "X-PatchVersion",
519 description = "Used only to communicate a PATCH version in a response for"
520 + " troubleshooting purposes only, and will not be provided by"
521 + " the client on request",
522 response = String.class),
523 @ResponseHeader(name = "X-LatestVersion",
524 description = "Used only to communicate an API's latest version",
525 response = String.class),
526 @ResponseHeader(name = "X-ONAP-RequestID",
527 description = "Used to track REST transactions for logging purpose",
528 response = UUID.class)
531 @Extension(name = "interface info", properties = {
532 @ExtensionProperty(name = "api-version", value = "1.0.0"),
533 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
536 @ApiResponses(value = {
537 @ApiResponse(code = 401, message = "Authentication Error"),
538 @ApiResponse(code = 403, message = "Authorization Error"),
539 @ApiResponse(code = 404, message = "Resource Not Found"),
540 @ApiResponse(code = 409, message = "Delete Conflict, Rule Violation"),
541 @ApiResponse(code = 500, message = "Internal Server Error")
543 public Response deleteSpecificVersionOfOperationalPolicy(
544 @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
545 @PathParam("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,
546 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
548 try (LegacyOperationalPolicyProvider operationalPolicyProvider = new LegacyOperationalPolicyProvider()) {
549 LegacyOperationalPolicy policy = operationalPolicyProvider
550 .deleteOperationalPolicy(policyId, policyVersion);
551 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
552 .entity(policy).build();
553 } catch (PfModelException | PfModelRuntimeException pfme) {
554 LOGGER.error("DELETE /policytypes/onap.policies.controlloop.Operational/versions/1.0.0/"
555 + "policies/{}/versions/{}", policyId, policyVersion, pfme);
556 return addLoggingHeaders(addVersionControlHeaders(
557 Response.status(pfme.getErrorResponse().getResponseCode())), requestId)
558 .entity(pfme.getErrorResponse()).build();
562 private ResponseBuilder addVersionControlHeaders(ResponseBuilder rb) {
563 return rb.header("X-MinorVersion", "0").header("X-PatchVersion", "0").header("X-LatestVersion", "1.0.0");
566 private ResponseBuilder addLoggingHeaders(ResponseBuilder rb, UUID requestId) {
567 if (requestId == null) {
568 // Generate a random uuid if client does not embed requestId in rest request
569 return rb.header("X-ONAP-RequestID", UUID.randomUUID());
571 return rb.header("X-ONAP-RequestID", requestId);