ed6e1d8c427b90da2e1d2230e30616d642d33fb2
[policy/api.git] / main / src / main / java / org / onap / policy / api / main / rest / LegacyApiRestController.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP Policy API
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  * SPDX-License-Identifier: Apache-2.0
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.policy.api.main.rest;
24
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.Map;
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
54 /**
55  * Class to provide legacy REST API services.
56  *
57  * @author Chenfei Gao (cgao@research.att.com)
58  */
59 @Path("/policy/api/v1")
60 @Api(value = "Legacy Policy Design API")
61 @Produces("application/json")
62 @Consumes("application/json")
63 public class LegacyApiRestController {
64
65     /**
66      * Retrieves all versions of a particular guard policy.
67      *
68      * @param policyId the ID of specified guard policy
69      *
70      * @return the Response object containing the results of the API operation
71      */
72     @GET
73     @Path("/policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/{policyId}")
74     @ApiOperation(value = "Retrieve all versions of a particular guard policy",
75             notes = "Returns a list of all versions of the specified guard policy",
76             response = LegacyGuardPolicyOutput.class, responseContainer = "Map",
77             responseHeaders = {
78                     @ResponseHeader(name = "X-MinorVersion",
79                                     description = "Used to request or communicate a MINOR version back from the client"
80                                                 + " to the server, and from the server back to the client",
81                                     response = String.class),
82                     @ResponseHeader(name = "X-PatchVersion",
83                                     description = "Used only to communicate a PATCH version in a response for"
84                                                 + " troubleshooting purposes only, and will not be provided by"
85                                                 + " the client on request",
86                                     response = String.class),
87                     @ResponseHeader(name = "X-LatestVersion",
88                                     description = "Used only to communicate an API's latest version",
89                                     response = String.class),
90                     @ResponseHeader(name = "X-ONAP-RequestID",
91                                     description = "Used to track REST transactions for logging purpose",
92                                     response = UUID.class)
93             },
94             authorizations = @Authorization(value = "basicAuth"),
95             tags = { "Legacy Guard Policy", },
96             extensions = {
97                     @Extension(name = "interface info", properties = {
98                             @ExtensionProperty(name = "api-version", value = "1.0.0"),
99                             @ExtensionProperty(name = "last-mod-release", value = "Dublin")
100                     })
101             })
102     @ApiResponses(value = {
103             @ApiResponse(code = 401, message = "Authentication Error"),
104             @ApiResponse(code = 403, message = "Authorization Error"),
105             @ApiResponse(code = 404, message = "Resource Not Found"),
106             @ApiResponse(code = 500, message = "Internal Server Error")
107         })
108     public Response getAllVersionsOfGuardPolicy(
109             @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
110             @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
111
112         try (LegacyGuardPolicyProvider guardPolicyProvider = new LegacyGuardPolicyProvider()) {
113             Map<String, LegacyGuardPolicyOutput> policies = guardPolicyProvider.fetchGuardPolicy(policyId, null);
114             return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
115                     .entity(policies).build();
116         } catch (PfModelException | PfModelRuntimeException pfme) {
117             return addLoggingHeaders(addVersionControlHeaders(
118                     Response.status(pfme.getErrorResponse().getResponseCode())), requestId)
119                     .entity(pfme.getErrorResponse()).build();
120         }
121     }
122
123     /**
124      * Retrieves the specified version of a particular guard policy.
125      *
126      * @param policyId the ID of specified policy
127      * @param policyVersion the version of specified policy
128      *
129      * @return the Response object containing the results of the API operation
130      */
131     @GET
132     @Path("/policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/{policyId}/versions/{policyVersion}")
133     @ApiOperation(value = "Retrieve one version of a particular guard policy",
134             notes = "Returns a particular version of a specified guard policy",
135             response = LegacyGuardPolicyOutput.class, responseContainer = "Map",
136             responseHeaders = {
137                     @ResponseHeader(name = "X-MinorVersion",
138                                     description = "Used to request or communicate a MINOR version back from the client"
139                                                 + " to the server, and from the server back to the client",
140                                     response = String.class),
141                     @ResponseHeader(name = "X-PatchVersion",
142                                     description = "Used only to communicate a PATCH version in a response for"
143                                                 + " troubleshooting purposes only, and will not be provided by"
144                                                 + " the client on request",
145                                     response = String.class),
146                     @ResponseHeader(name = "X-LatestVersion",
147                                     description = "Used only to communicate an API's latest version",
148                                     response = String.class),
149                     @ResponseHeader(name = "X-ONAP-RequestID",
150                                     description = "Used to track REST transactions for logging purpose",
151                                     response = UUID.class)
152             },
153             authorizations = @Authorization(value = "basicAuth"),
154             tags = { "Legacy Guard Policy", },
155             extensions = {
156                     @Extension(name = "interface info", properties = {
157                             @ExtensionProperty(name = "api-version", value = "1.0.0"),
158                             @ExtensionProperty(name = "last-mod-release", value = "Dublin")
159                     })
160             })
161     @ApiResponses(value = {
162             @ApiResponse(code = 401, message = "Authentication Error"),
163             @ApiResponse(code = 403, message = "Authorization Error"),
164             @ApiResponse(code = 404, message = "Resource Not Found"),
165             @ApiResponse(code = 500, message = "Internal Server Error")
166         })
167     public Response getSpecificVersionOfGuardPolicy(
168             @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
169             @PathParam("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,
170             @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
171
172         try (LegacyGuardPolicyProvider guardPolicyProvider = new LegacyGuardPolicyProvider()) {
173             Map<String, LegacyGuardPolicyOutput> policies = guardPolicyProvider
174                     .fetchGuardPolicy(policyId, policyVersion);
175             return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
176                     .entity(policies).build();
177         } catch (PfModelException | PfModelRuntimeException pfme) {
178             return addLoggingHeaders(addVersionControlHeaders(
179                     Response.status(pfme.getErrorResponse().getResponseCode())), requestId)
180                     .entity(pfme.getErrorResponse()).build();
181         }
182     }
183
184     /**
185      * Creates a new guard policy.
186      *
187      * @param body the body of policy
188      *
189      * @return the Response object containing the results of the API operation
190      */
191     @POST
192     @Path("/policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies")
193     @ApiOperation(value = "Create a new guard policy",
194             notes = "Client should provide entity body of the new guard policy",
195             authorizations = @Authorization(value = "basicAuth"),
196             tags = { "Legacy Guard Policy", },
197             response = LegacyGuardPolicyOutput.class, responseContainer = "Map",
198             responseHeaders = {
199                     @ResponseHeader(name = "X-MinorVersion",
200                                     description = "Used to request or communicate a MINOR version back from the client"
201                                                 + " to the server, and from the server back to the client",
202                                     response = String.class),
203                     @ResponseHeader(name = "X-PatchVersion",
204                                     description = "Used only to communicate a PATCH version in a response for"
205                                                 + " troubleshooting purposes only, and will not be provided by"
206                                                 + " the client on request",
207                                     response = String.class),
208                     @ResponseHeader(name = "X-LatestVersion",
209                                     description = "Used only to communicate an API's latest version",
210                                     response = String.class),
211                     @ResponseHeader(name = "X-ONAP-RequestID",
212                                     description = "Used to track REST transactions for logging purpose",
213                                     response = UUID.class)
214             },
215             extensions = {
216                     @Extension(name = "interface info", properties = {
217                             @ExtensionProperty(name = "api-version", value = "1.0.0"),
218                             @ExtensionProperty(name = "last-mod-release", value = "Dublin")
219                     })
220             })
221     @ApiResponses(value = {
222             @ApiResponse(code = 400, message = "Invalid Body"),
223             @ApiResponse(code = 401, message = "Authentication Error"),
224             @ApiResponse(code = 403, message = "Authorization Error"),
225             @ApiResponse(code = 500, message = "Internal Server Error")
226         })
227     public Response createGuardPolicy(
228             @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId,
229             @ApiParam(value = "Entity body of policy", required = true) LegacyGuardPolicyInput body) {
230
231         try (LegacyGuardPolicyProvider guardPolicyProvider = new LegacyGuardPolicyProvider()) {
232             Map<String, LegacyGuardPolicyOutput> policy = guardPolicyProvider.createGuardPolicy(body);
233             return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
234                     .entity(policy).build();
235         } catch (PfModelException | PfModelRuntimeException pfme) {
236             return addLoggingHeaders(addVersionControlHeaders(
237                     Response.status(pfme.getErrorResponse().getResponseCode())), requestId)
238                     .entity(pfme.getErrorResponse()).build();
239         }
240     }
241
242     /**
243      * Deletes the specified version of a particular guard policy.
244      *
245      * @param policyId the ID of specified policy
246      * @param policyVersion the version of specified policy
247      *
248      * @return the Response object containing the results of the API operation
249      */
250     @DELETE
251     @Path("/policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/{policyId}/versions/{policyVersion}")
252     @ApiOperation(value = "Delete a particular version of a guard policy",
253             notes = "Rule: the version that has been deployed in PDP group(s) cannot be deleted",
254             authorizations = @Authorization(value = "basicAuth"),
255             tags = { "Legacy Guard Policy", },
256             response = LegacyGuardPolicyOutput.class, responseContainer = "Map",
257             responseHeaders = {
258                     @ResponseHeader(name = "X-MinorVersion",
259                                     description = "Used to request or communicate a MINOR version back from the client"
260                                                 + " to the server, and from the server back to the client",
261                                     response = String.class),
262                     @ResponseHeader(name = "X-PatchVersion",
263                                     description = "Used only to communicate a PATCH version in a response for"
264                                                 + " troubleshooting purposes only, and will not be provided by"
265                                                 + " the client on request",
266                                     response = String.class),
267                     @ResponseHeader(name = "X-LatestVersion",
268                                     description = "Used only to communicate an API's latest version",
269                                     response = String.class),
270                     @ResponseHeader(name = "X-ONAP-RequestID",
271                                     description = "Used to track REST transactions for logging purpose",
272                                     response = UUID.class)
273             },
274             extensions = {
275                     @Extension(name = "interface info", properties = {
276                             @ExtensionProperty(name = "api-version", value = "1.0.0"),
277                             @ExtensionProperty(name = "last-mod-release", value = "Dublin")
278                     })
279             })
280     @ApiResponses(value = {
281             @ApiResponse(code = 401, message = "Authentication Error"),
282             @ApiResponse(code = 403, message = "Authorization Error"),
283             @ApiResponse(code = 404, message = "Resource Not Found"),
284             @ApiResponse(code = 409, message = "Delete Conflict, Rule Violation"),
285             @ApiResponse(code = 500, message = "Internal Server Error")
286         })
287     public Response deleteSpecificVersionOfGuardPolicy(
288             @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
289             @PathParam("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,
290             @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
291
292         try (LegacyGuardPolicyProvider guardPolicyProvider = new LegacyGuardPolicyProvider()) {
293             Map<String, LegacyGuardPolicyOutput> policies = guardPolicyProvider
294                     .deleteGuardPolicy(policyId, policyVersion);
295             return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
296                     .entity(policies).build();
297         } catch (PfModelException | PfModelRuntimeException pfme) {
298             return addLoggingHeaders(addVersionControlHeaders(
299                     Response.status(pfme.getErrorResponse().getResponseCode())), requestId)
300                     .entity(pfme.getErrorResponse()).build();
301         }
302     }
303
304     /**
305      * Retrieves all versions of a particular operational policy.
306      *
307      * @param policyId the ID of specified operational policy
308      *
309      * @return the Response object containing the results of the API operation
310      */
311     @GET
312     @Path("/policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies/{policyId}")
313     @ApiOperation(value = "Retrieve all versions of a particular operational policy",
314             notes = "Returns a list of all versions of the specified operational policy",
315             response = LegacyOperationalPolicy.class,
316             responseHeaders = {
317                     @ResponseHeader(name = "X-MinorVersion",
318                                     description = "Used to request or communicate a MINOR version back from the client"
319                                                 + " to the server, and from the server back to the client",
320                                     response = String.class),
321                     @ResponseHeader(name = "X-PatchVersion",
322                                     description = "Used only to communicate a PATCH version in a response for"
323                                                 + " troubleshooting purposes only, and will not be provided by"
324                                                 + " the client on request",
325                                     response = String.class),
326                     @ResponseHeader(name = "X-LatestVersion",
327                                     description = "Used only to communicate an API's latest version",
328                                     response = String.class),
329                     @ResponseHeader(name = "X-ONAP-RequestID",
330                                     description = "Used to track REST transactions for logging purpose",
331                                     response = UUID.class)
332             },
333             authorizations = @Authorization(value = "basicAuth"),
334             tags = { "Legacy Operational Policy", },
335             extensions = {
336                     @Extension(name = "interface info", properties = {
337                             @ExtensionProperty(name = "api-version", value = "1.0.0"),
338                             @ExtensionProperty(name = "last-mod-release", value = "Dublin")
339                     })
340             })
341     @ApiResponses(value = {
342             @ApiResponse(code = 401, message = "Authentication Error"),
343             @ApiResponse(code = 403, message = "Authorization Error"),
344             @ApiResponse(code = 404, message = "Resource Not Found"),
345             @ApiResponse(code = 500, message = "Internal Server Error")
346         })
347     public Response getAllVersionsOfOperationalPolicy(
348             @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
349             @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
350
351         try (LegacyOperationalPolicyProvider operationalPolicyProvider = new LegacyOperationalPolicyProvider()) {
352             LegacyOperationalPolicy policy = operationalPolicyProvider.fetchOperationalPolicy(policyId, null);
353             return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
354                     .entity(policy).build();
355         } catch (PfModelException | PfModelRuntimeException pfme) {
356             return addLoggingHeaders(addVersionControlHeaders(
357                     Response.status(pfme.getErrorResponse().getResponseCode())), requestId)
358                     .entity(pfme.getErrorResponse()).build();
359         }
360     }
361
362     /**
363      * Retrieves the specified version of a particular operational policy.
364      *
365      * @param policyId the ID of specified policy
366      * @param policyVersion the version of specified policy
367      *
368      * @return the Response object containing the results of the API operation
369      */
370     @GET
371     @Path("/policytypes/onap.policies.controlloop.Operational/versions/1.0.0/"
372          + "policies/{policyId}/versions/{policyVersion}")
373     @ApiOperation(value = "Retrieve one version of a particular operational policy",
374             notes = "Returns a particular version of a specified operational policy",
375             response = LegacyOperationalPolicy.class,
376             responseHeaders = {
377                     @ResponseHeader(name = "X-MinorVersion",
378                                     description = "Used to request or communicate a MINOR version back from the client"
379                                                 + " to the server, and from the server back to the client",
380                                     response = String.class),
381                     @ResponseHeader(name = "X-PatchVersion",
382                                     description = "Used only to communicate a PATCH version in a response for"
383                                                 + " troubleshooting purposes only, and will not be provided by"
384                                                 + " the client on request",
385                                     response = String.class),
386                     @ResponseHeader(name = "X-LatestVersion",
387                                     description = "Used only to communicate an API's latest version",
388                                     response = String.class),
389                     @ResponseHeader(name = "X-ONAP-RequestID",
390                                     description = "Used to track REST transactions for logging purpose",
391                                     response = UUID.class)
392             },
393             authorizations = @Authorization(value = "basicAuth"),
394             tags = { "Legacy Operational Policy", },
395             extensions = {
396                     @Extension(name = "interface info", properties = {
397                             @ExtensionProperty(name = "api-version", value = "1.0.0"),
398                             @ExtensionProperty(name = "last-mod-release", value = "Dublin")
399                     })
400             })
401     @ApiResponses(value = {
402             @ApiResponse(code = 401, message = "Authentication Error"),
403             @ApiResponse(code = 403, message = "Authorization Error"),
404             @ApiResponse(code = 404, message = "Resource Not Found"),
405             @ApiResponse(code = 500, message = "Internal Server Error")
406         })
407     public Response getSpecificVersionOfOperationalPolicy(
408             @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
409             @PathParam("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,
410             @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
411
412         try (LegacyOperationalPolicyProvider operationalPolicyProvider = new LegacyOperationalPolicyProvider()) {
413             LegacyOperationalPolicy policy = operationalPolicyProvider.fetchOperationalPolicy(policyId, policyVersion);
414             return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
415                     .entity(policy).build();
416         } catch (PfModelException | PfModelRuntimeException pfme) {
417             return addLoggingHeaders(addVersionControlHeaders(
418                     Response.status(pfme.getErrorResponse().getResponseCode())), requestId)
419                     .entity(pfme.getErrorResponse()).build();
420         }
421     }
422
423     /**
424      * Creates a new operational policy.
425      *
426      * @param body the body of policy
427      *
428      * @return the Response object containing the results of the API operation
429      */
430     @POST
431     @Path("/policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies")
432     @ApiOperation(value = "Create a new operational policy",
433             notes = "Client should provide entity body of the new operational policy",
434             authorizations = @Authorization(value = "basicAuth"),
435             tags = { "Legacy Operational Policy", },
436             response = LegacyOperationalPolicy.class,
437             responseHeaders = {
438                     @ResponseHeader(name = "X-MinorVersion",
439                                     description = "Used to request or communicate a MINOR version back from the client"
440                                                 + " to the server, and from the server back to the client",
441                                     response = String.class),
442                     @ResponseHeader(name = "X-PatchVersion",
443                                     description = "Used only to communicate a PATCH version in a response for"
444                                                 + " troubleshooting purposes only, and will not be provided by"
445                                                 + " the client on request",
446                                     response = String.class),
447                     @ResponseHeader(name = "X-LatestVersion",
448                                     description = "Used only to communicate an API's latest version",
449                                     response = String.class),
450                     @ResponseHeader(name = "X-ONAP-RequestID",
451                                     description = "Used to track REST transactions for logging purpose",
452                                     response = UUID.class)
453             },
454             extensions = {
455                     @Extension(name = "interface info", properties = {
456                             @ExtensionProperty(name = "api-version", value = "1.0.0"),
457                             @ExtensionProperty(name = "last-mod-release", value = "Dublin")
458                     })
459             })
460     @ApiResponses(value = {
461             @ApiResponse(code = 400, message = "Invalid Body"),
462             @ApiResponse(code = 401, message = "Authentication Error"),
463             @ApiResponse(code = 403, message = "Authorization Error"),
464             @ApiResponse(code = 500, message = "Internal Server Error")
465         })
466     public Response createOperationalPolicy(
467             @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId,
468             @ApiParam(value = "Entity body of policy", required = true) LegacyOperationalPolicy body) {
469
470         try (LegacyOperationalPolicyProvider operationalPolicyProvider = new LegacyOperationalPolicyProvider()) {
471             LegacyOperationalPolicy policy = operationalPolicyProvider.createOperationalPolicy(body);
472             return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
473                     .entity(policy).build();
474         } catch (PfModelException | PfModelRuntimeException pfme) {
475             return addLoggingHeaders(addVersionControlHeaders(
476                     Response.status(pfme.getErrorResponse().getResponseCode())), requestId)
477                     .entity(pfme.getErrorResponse()).build();
478         }
479     }
480
481     /**
482      * Deletes the specified version of a particular operational policy.
483      *
484      * @param policyId the ID of specified policy
485      * @param policyVersion the version of specified policy
486      *
487      * @return the Response object containing the results of the API operation
488      */
489     @DELETE
490     @Path("/policytypes/onap.policies.controlloop.Operational/versions/1.0.0/"
491          + "policies/{policyId}/versions/{policyVersion}")
492     @ApiOperation(value = "Delete a particular version of a specified operational policy",
493             notes = "Rule: the version that has been deployed in PDP group(s) cannot be deleted",
494             authorizations = @Authorization(value = "basicAuth"),
495             tags = { "Legacy Operational Policy", },
496             response = LegacyOperationalPolicy.class,
497             responseHeaders = {
498                     @ResponseHeader(name = "X-MinorVersion",
499                                     description = "Used to request or communicate a MINOR version back from the client"
500                                                 + " to the server, and from the server back to the client",
501                                     response = String.class),
502                     @ResponseHeader(name = "X-PatchVersion",
503                                     description = "Used only to communicate a PATCH version in a response for"
504                                                 + " troubleshooting purposes only, and will not be provided by"
505                                                 + " the client on request",
506                                     response = String.class),
507                     @ResponseHeader(name = "X-LatestVersion",
508                                     description = "Used only to communicate an API's latest version",
509                                     response = String.class),
510                     @ResponseHeader(name = "X-ONAP-RequestID",
511                                     description = "Used to track REST transactions for logging purpose",
512                                     response = UUID.class)
513             },
514             extensions = {
515                     @Extension(name = "interface info", properties = {
516                             @ExtensionProperty(name = "api-version", value = "1.0.0"),
517                             @ExtensionProperty(name = "last-mod-release", value = "Dublin")
518                     })
519             })
520     @ApiResponses(value = {
521             @ApiResponse(code = 401, message = "Authentication Error"),
522             @ApiResponse(code = 403, message = "Authorization Error"),
523             @ApiResponse(code = 404, message = "Resource Not Found"),
524             @ApiResponse(code = 409, message = "Delete Conflict, Rule Violation"),
525             @ApiResponse(code = 500, message = "Internal Server Error")
526         })
527     public Response deleteSpecificVersionOfOperationalPolicy(
528             @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
529             @PathParam("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,
530             @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
531
532         try (LegacyOperationalPolicyProvider operationalPolicyProvider = new LegacyOperationalPolicyProvider()) {
533             LegacyOperationalPolicy policy = operationalPolicyProvider
534                     .deleteOperationalPolicy(policyId, policyVersion);
535             return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
536                     .entity(policy).build();
537         } catch (PfModelException | PfModelRuntimeException pfme) {
538             return addLoggingHeaders(addVersionControlHeaders(
539                     Response.status(pfme.getErrorResponse().getResponseCode())), requestId)
540                     .entity(pfme.getErrorResponse()).build();
541         }
542     }
543
544     private ResponseBuilder addVersionControlHeaders(ResponseBuilder rb) {
545         return rb.header("X-MinorVersion", "0").header("X-PatchVersion", "0").header("X-LatestVersion", "1.0.0");
546     }
547
548     private ResponseBuilder addLoggingHeaders(ResponseBuilder rb, UUID requestId) {
549         if (requestId == null) {
550             // Generate a random uuid if client does not embed requestId in rest request
551             return rb.header("X-ONAP-RequestID", UUID.randomUUID());
552         }
553         return rb.header("X-ONAP-RequestID", requestId);
554     }
555 }