8e00b436ea00ec363efa71db7179cc13aea1e312
[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.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;
50
51 /**
52  * Class to provide legacy REST API services.
53  *
54  * @author Chenfei Gao (cgao@research.att.com)
55  */
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 {
61
62     /**
63      * Retrieves all versions of guard policies.
64      *
65      * @return the Response object containing the results of the API operation
66      */
67     @GET
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,
73             responseHeaders = {
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)
89             },
90             authorizations = @Authorization(value = "basicAuth"),
91             tags = { "Legacy Guard Policy", },
92             extensions = {
93                     @Extension(name = "interface info", properties = {
94                             @ExtensionProperty(name = "api-version", value = "1.0.0"),
95                             @ExtensionProperty(name = "last-mod-release", value = "Dublin")
96                     })
97             })
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")
102         })
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();
107     }
108
109     /**
110      * Retrieves all versions of a particular guard policy.
111      *
112      * @param policyId the ID of specified guard policy
113      *
114      * @return the Response object containing the results of the API operation
115      */
116     @GET
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,
122             responseHeaders = {
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)
138             },
139             authorizations = @Authorization(value = "basicAuth"),
140             tags = { "Legacy Guard Policy", },
141             extensions = {
142                     @Extension(name = "interface info", properties = {
143                             @ExtensionProperty(name = "api-version", value = "1.0.0"),
144                             @ExtensionProperty(name = "last-mod-release", value = "Dublin")
145                     })
146             })
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")
152         })
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();
158     }
159
160     /**
161      * Retrieves the specified version of a particular guard policy.
162      *
163      * @param policyId the ID of specified policy
164      * @param policyVersion the version of specified policy
165      *
166      * @return the Response object containing the results of the API operation
167      */
168     @GET
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,
174             responseHeaders = {
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)
190             },
191             authorizations = @Authorization(value = "basicAuth"),
192             tags = { "Legacy Guard Policy", },
193             extensions = {
194                     @Extension(name = "interface info", properties = {
195                             @ExtensionProperty(name = "api-version", value = "1.0.0"),
196                             @ExtensionProperty(name = "last-mod-release", value = "Dublin")
197                     })
198             })
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")
204         })
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();
211     }
212
213     /**
214      * Creates a new guard policy.
215      *
216      * @param body the body of policy
217      *
218      * @return the Response object containing the results of the API operation
219      */
220     @POST
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,
229             responseHeaders = {
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)
245             },
246             extensions = {
247                     @Extension(name = "interface info", properties = {
248                             @ExtensionProperty(name = "api-version", value = "1.0.0"),
249                             @ExtensionProperty(name = "last-mod-release", value = "Dublin")
250                     })
251             })
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")
257         })
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();
263     }
264
265     /**
266      * Deletes all versions of a particular guard policy.
267      *
268      * @param policyId the ID of specified policy
269      *
270      * @return the Response object containing the results of the API operation
271      */
272     @DELETE
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", },
278             extensions = {
279                     @Extension(name = "interface info", properties = {
280                             @ExtensionProperty(name = "api-version", value = "1.0.0"),
281                             @ExtensionProperty(name = "last-mod-release", value = "Dublin")
282                     })
283             })
284     @ApiResponses(value = {
285             @ApiResponse(code = 204, message = "Resources successfully deleted, no content returned",
286             responseHeaders = {
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)
302             }),
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")
308         })
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();
314     }
315
316     /**
317      * Deletes the specified version of a particular guard policy.
318      *
319      * @param policyId the ID of specified policy
320      * @param policyVersion the version of specified policy
321      *
322      * @return the Response object containing the results of the API operation
323      */
324     @DELETE
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", },
330             extensions = {
331                     @Extension(name = "interface info", properties = {
332                             @ExtensionProperty(name = "api-version", value = "1.0.0"),
333                             @ExtensionProperty(name = "last-mod-release", value = "Dublin")
334                     })
335             })
336     @ApiResponses(value = {
337             @ApiResponse(code = 204, message = "Resource successfully deleted, no content returned",
338             responseHeaders = {
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)
354             }),
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")
360         })
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();
367     }
368
369     /**
370      * Retrieves all versions of operational policies.
371      *
372      * @return the Response object containing the results of the API operation
373      */
374     @GET
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,
380             responseHeaders = {
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)
396             },
397             authorizations = @Authorization(value = "basicAuth"),
398             tags = { "Legacy Operational Policy", },
399             extensions = {
400                     @Extension(name = "interface info", properties = {
401                             @ExtensionProperty(name = "api-version", value = "1.0.0"),
402                             @ExtensionProperty(name = "last-mod-release", value = "Dublin")
403                     })
404             })
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")
409         })
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();
414     }
415
416     /**
417      * Retrieves all versions of a particular operational policy.
418      *
419      * @param policyId the ID of specified operational policy
420      *
421      * @return the Response object containing the results of the API operation
422      */
423     @GET
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,
429             responseHeaders = {
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)
445             },
446             authorizations = @Authorization(value = "basicAuth"),
447             tags = { "Legacy Operational Policy", },
448             extensions = {
449                     @Extension(name = "interface info", properties = {
450                             @ExtensionProperty(name = "api-version", value = "1.0.0"),
451                             @ExtensionProperty(name = "last-mod-release", value = "Dublin")
452                     })
453             })
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")
459         })
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();
465     }
466
467     /**
468      * Retrieves the specified version of a particular operational policy.
469      *
470      * @param policyId the ID of specified policy
471      * @param policyVersion the version of specified policy
472      *
473      * @return the Response object containing the results of the API operation
474      */
475     @GET
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,
482             responseHeaders = {
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)
498             },
499             authorizations = @Authorization(value = "basicAuth"),
500             tags = { "Legacy Operational Policy", },
501             extensions = {
502                     @Extension(name = "interface info", properties = {
503                             @ExtensionProperty(name = "api-version", value = "1.0.0"),
504                             @ExtensionProperty(name = "last-mod-release", value = "Dublin")
505                     })
506             })
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")
512         })
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();
519     }
520
521     /**
522      * Creates a new operational policy.
523      *
524      * @param body the body of policy
525      *
526      * @return the Response object containing the results of the API operation
527      */
528     @POST
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,
537             responseHeaders = {
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)
553             },
554             extensions = {
555                     @Extension(name = "interface info", properties = {
556                             @ExtensionProperty(name = "api-version", value = "1.0.0"),
557                             @ExtensionProperty(name = "last-mod-release", value = "Dublin")
558                     })
559             })
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")
565         })
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();
571     }
572
573     /**
574      * Deletes all versions of a particular operational policy.
575      *
576      * @param policyId the ID of specified policy
577      *
578      * @return the Response object containing the results of the API operation
579      */
580     @DELETE
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", },
586             extensions = {
587                     @Extension(name = "interface info", properties = {
588                             @ExtensionProperty(name = "api-version", value = "1.0.0"),
589                             @ExtensionProperty(name = "last-mod-release", value = "Dublin")
590                     })
591             })
592     @ApiResponses(value = {
593             @ApiResponse(code = 204, message = "Resources successfully deleted, no content returned",
594             responseHeaders = {
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)
610             }),
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")
616         })
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();
622     }
623
624     /**
625      * Deletes the specified version of a particular operational policy.
626      *
627      * @param policyId the ID of specified policy
628      * @param policyVersion the version of specified policy
629      *
630      * @return the Response object containing the results of the API operation
631      */
632     @DELETE
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", },
639             extensions = {
640                     @Extension(name = "interface info", properties = {
641                             @ExtensionProperty(name = "api-version", value = "1.0.0"),
642                             @ExtensionProperty(name = "last-mod-release", value = "Dublin")
643                     })
644             })
645     @ApiResponses(value = {
646             @ApiResponse(code = 204, message = "Resource successfully deleted, no content returned",
647             responseHeaders = {
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)
663             }),
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")
669         })
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();
676     }
677
678     private ResponseBuilder addVersionControlHeaders(ResponseBuilder rb) {
679         return rb.header("X-MinorVersion", "0").header("X-PatchVersion", "0").header("X-LatestVersion", "1.0.0");
680     }
681
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());
686         }
687         return rb.header("X-ONAP-RequestID", requestId);
688     }
689 }