aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/main/java/org/onap/policy/api/main/rest/ApiRestController.java
blob: 79d8a64af5e4047f1e4107eb9067a4ad58ab48b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
/*-
 * ============LICENSE_START=======================================================
 * ONAP Policy API
 * ================================================================================
 * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
 * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
 * Modifications Copyright (C) 2020 Nordix Foundation.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * SPDX-License-Identifier: Apache-2.0
 * ============LICENSE_END=========================================================
 */

package org.onap.policy.api.main.rest;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import io.swagger.annotations.Authorization;
import io.swagger.annotations.BasicAuthDefinition;
import io.swagger.annotations.Extension;
import io.swagger.annotations.ExtensionProperty;
import io.swagger.annotations.Info;
import io.swagger.annotations.ResponseHeader;
import io.swagger.annotations.SecurityDefinition;
import io.swagger.annotations.SwaggerDefinition;
import java.util.UUID;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response;
import org.onap.policy.api.main.rest.provider.HealthCheckProvider;
import org.onap.policy.api.main.rest.provider.PolicyProvider;
import org.onap.policy.api.main.rest.provider.PolicyTypeProvider;
import org.onap.policy.api.main.rest.provider.StatisticsProvider;
import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
import org.onap.policy.common.endpoints.report.HealthCheckReport;
import org.onap.policy.common.endpoints.utils.NetLoggerUtil;
import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.base.PfModelRuntimeException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Class to provide REST API services.
 *
 * @author Chenfei Gao (cgao@research.att.com)
 */
@Path("/policy/api/v1")
@Api(value = "Policy Design API")
@Produces({"application/json", "application/yaml"})
@Consumes({"application/json", "application/yaml"})
@SwaggerDefinition(
    info = @Info(
        description = "Policy Design API is publicly exposed for clients to Create/Read/Update/Delete"
            + " policy types, policy type implementation and policies which can be recognized"
            + " and executable by incorporated policy engines. It is an"
            + " independent component running rest service that takes all policy design API calls"
            + " from clients and then assign them to different API working functions. Besides"
            + " that, API is also exposed for clients to retrieve healthcheck status of this API"
            + " rest service and the statistics report including the counters of API invocation.",
        version = "1.0.0", title = "Policy Design",
        extensions = {@Extension(properties = {@ExtensionProperty(name = "planned-retirement-date", value = "tbd"),
            @ExtensionProperty(name = "component", value = "Policy Framework")})}),
    schemes = {SwaggerDefinition.Scheme.HTTP, SwaggerDefinition.Scheme.HTTPS},
    securityDefinition = @SecurityDefinition(basicAuthDefinitions = {@BasicAuthDefinition(key = "basicAuth")}))
public class ApiRestController extends CommonRestController {

    private static final Logger LOGGER = LoggerFactory.getLogger(ApiRestController.class);

    /**
     * Retrieves the healthcheck status of the API component.
     *
     * @return the Response object containing the results of the API operation
     */
    @GET
    @Path("/healthcheck")
    @ApiOperation(value = "Perform a system healthcheck", notes = "Returns healthy status of the Policy API component",
        response = HealthCheckReport.class,
        responseHeaders = {
            @ResponseHeader(name = "X-MinorVersion",
                description = "Used to request or communicate a MINOR version back from the client"
                    + " to the server, and from the server back to the client",
                response = String.class),
            @ResponseHeader(name = "X-PatchVersion",
                description = "Used only to communicate a PATCH version in a response for"
                    + " troubleshooting purposes only, and will not be provided by" + " the client on request",
                response = String.class),
            @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version",
                response = String.class),
            @ResponseHeader(name = "X-ONAP-RequestID",
                description = "Used to track REST transactions for logging purpose", response = UUID.class)},
        authorizations = @Authorization(value = "basicAuth"), tags = {"HealthCheck", },
        extensions = {
            @Extension(name = "interface info", properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
                @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
    @ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"),
        @ApiResponse(code = 403, message = "Authorization Error"),
        @ApiResponse(code = 500, message = "Internal Server Error")})
    public Response
        getHealthCheck(@HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {

        updateApiStatisticsCounter(Target.OTHER, Result.SUCCESS, HttpMethod.GET);
        return makeOkResponse(requestId, new HealthCheckProvider().performHealthCheck());
    }

    /**
     * Retrieves the statistics report of the API component.
     *
     * @return the Response object containing the results of the API operation
     */
    @GET
    @Path("/statistics")
    @ApiOperation(value = "Retrieve current statistics",
        notes = "Returns current statistics including the counters of API invocation",
        response = StatisticsReport.class,
        responseHeaders = {
            @ResponseHeader(name = "X-MinorVersion",
                description = "Used to request or communicate a MINOR version back from the client"
                    + " to the server, and from the server back to the client",
                response = String.class),
            @ResponseHeader(name = "X-PatchVersion",
                description = "Used only to communicate a PATCH version in a response for"
                    + " troubleshooting purposes only, and will not be provided by" + " the client on request",
                response = String.class),
            @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version",
                response = String.class),
            @ResponseHeader(name = "X-ONAP-RequestID",
                description = "Used to track REST transactions for logging purpose", response = UUID.class)},
        authorizations = @Authorization(value = "basicAuth"), tags = {"Statistics", },
        extensions = {
            @Extension(name = "interface info", properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
                @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
    @ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"),
        @ApiResponse(code = 403, message = "Authorization Error"),
        @ApiResponse(code = 500, message = "Internal Server Error")})
    public Response
        getStatistics(@HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {

        updateApiStatisticsCounter(Target.OTHER, Result.SUCCESS, HttpMethod.GET);

        return makeOkResponse(requestId, new StatisticsProvider().fetchCurrentStatistics());
    }

    /**
     * Retrieves all available policy types.
     *
     * @return the Response object containing the results of the API operation
     */
    @GET
    @Path("/policytypes")
    @ApiOperation(value = "Retrieve existing policy types",
        notes = "Returns a list of existing policy types stored in Policy Framework",
        response = ToscaServiceTemplate.class,
        responseHeaders = {
            @ResponseHeader(name = "X-MinorVersion",
                description = "Used to request or communicate a MINOR version back from the client"
                    + " to the server, and from the server back to the client",
                response = String.class),
            @ResponseHeader(name = "X-PatchVersion",
                description = "Used only to communicate a PATCH version in a response for"
                    + " troubleshooting purposes only, and will not be provided by" + " the client on request",
                response = String.class),
            @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version",
                response = String.class),
            @ResponseHeader(name = "X-ONAP-RequestID",
                description = "Used to track REST transactions for logging purpose", response = UUID.class)},
        authorizations = @Authorization(value = "basicAuth"), tags = {"PolicyType", },
        extensions = {
            @Extension(name = "interface info", properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
                @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
    @ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"),
        @ApiResponse(code = 403, message = "Authorization Error"),
        @ApiResponse(code = 500, message = "Internal Server Error")})
    public Response
        getAllPolicyTypes(@HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {

        try (PolicyTypeProvider policyTypeProvider = new PolicyTypeProvider()) {
            ToscaServiceTemplate serviceTemplate = policyTypeProvider.fetchPolicyTypes(null, null);
            updateApiStatisticsCounter(Target.POLICY_TYPE, Result.SUCCESS, HttpMethod.GET);
            return makeOkResponse(requestId, serviceTemplate);
        } catch (PfModelException | PfModelRuntimeException pfme) {
            LOGGER.debug("GET /policytypes", pfme);
            updateApiStatisticsCounter(Target.POLICY_TYPE, Result.FAILURE, HttpMethod.GET);
            return makeErrorResponse(requestId, pfme);
        }
    }

    /**
     * Retrieves all versions of a particular policy type.
     *
     * @param policyTypeId the ID of specified policy type
     *
     * @return the Response object containing the results of the API operation
     */
    @GET
    @Path("/policytypes/{policyTypeId}")
    @ApiOperation(value = "Retrieve all available versions of a policy type",
        notes = "Returns a list of all available versions for the specified policy type",
        response = ToscaServiceTemplate.class,
        responseHeaders = {
            @ResponseHeader(name = "X-MinorVersion",
                description = "Used to request or communicate a MINOR version back from the client"
                    + " to the server, and from the server back to the client",
                response = String.class),
            @ResponseHeader(name = "X-PatchVersion",
                description = "Used only to communicate a PATCH version in a response for"
                    + " troubleshooting purposes only, and will not be provided by" + " the client on request",
                response = String.class),
            @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version",
                response = String.class),
            @ResponseHeader(name = "X-ONAP-RequestID",
                description = "Used to track REST transactions for logging purpose", response = UUID.class)},
        authorizations = @Authorization(value = "basicAuth"), tags = {"PolicyType", },
        extensions = {
            @Extension(name = "interface info", properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
                @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
    @ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"),
        @ApiResponse(code = 403, message = "Authorization Error"),
        @ApiResponse(code = 404, message = "Resource Not Found"),
        @ApiResponse(code = 500, message = "Internal Server Error")})
    public Response getAllVersionsOfPolicyType(
        @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
        @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {

        try (PolicyTypeProvider policyTypeProvider = new PolicyTypeProvider()) {
            ToscaServiceTemplate serviceTemplate = policyTypeProvider.fetchPolicyTypes(policyTypeId, null);
            updateApiStatisticsCounter(Target.POLICY_TYPE, Result.SUCCESS, HttpMethod.GET);
            return makeOkResponse(requestId, serviceTemplate);
        } catch (PfModelException | PfModelRuntimeException pfme) {
            LOGGER.debug("GET /policytypes/{}", policyTypeId, pfme);
            updateApiStatisticsCounter(Target.POLICY_TYPE, Result.FAILURE, HttpMethod.GET);
            return makeErrorResponse(requestId, pfme);
        }
    }

    /**
     * Retrieves specified version of a particular policy type.
     *
     * @param policyTypeId the ID of specified policy type
     * @param versionId the version of specified policy type
     *
     * @return the Response object containing the results of the API operation
     */
    @GET
    @Path("/policytypes/{policyTypeId}/versions/{versionId}")
    @ApiOperation(value = "Retrieve one particular version of a policy type",
        notes = "Returns a particular version for the specified policy type", response = ToscaServiceTemplate.class,
        responseHeaders = {
            @ResponseHeader(name = "X-MinorVersion",
                description = "Used to request or communicate a MINOR version back from the client"
                    + " to the server, and from the server back to the client",
                response = String.class),
            @ResponseHeader(name = "X-PatchVersion",
                description = "Used only to communicate a PATCH version in a response for"
                    + " troubleshooting purposes only, and will not be provided by" + " the client on request",
                response = String.class),
            @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version",
                response = String.class),
            @ResponseHeader(name = "X-ONAP-RequestID",
                description = "Used to track REST transactions for logging purpose", response = UUID.class)},
        authorizations = @Authorization(value = "basicAuth"), tags = {"PolicyType", },
        extensions = {
            @Extension(name = "interface info", properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
                @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
    @ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"),
        @ApiResponse(code = 403, message = "Authorization Error"),
        @ApiResponse(code = 404, message = "Resource Not Found"),
        @ApiResponse(code = 500, message = "Internal Server Error")})
    public Response getSpecificVersionOfPolicyType(
        @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
        @PathParam("versionId") @ApiParam(value = "Version of policy type", required = true) String versionId,
        @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {

        try (PolicyTypeProvider policyTypeProvider = new PolicyTypeProvider()) {
            ToscaServiceTemplate serviceTemplate = policyTypeProvider.fetchPolicyTypes(policyTypeId, versionId);
            updateApiStatisticsCounter(Target.POLICY_TYPE, Result.SUCCESS, HttpMethod.GET);
            return makeOkResponse(requestId, serviceTemplate);
        } catch (PfModelException | PfModelRuntimeException pfme) {
            LOGGER.debug("GET /policytypes/{}/versions/{}", policyTypeId, versionId, pfme);
            updateApiStatisticsCounter(Target.POLICY_TYPE, Result.FAILURE, HttpMethod.GET);
            return makeErrorResponse(requestId, pfme);
        }
    }

    /**
     * Retrieves latest version of a particular policy type.
     *
     * @param policyTypeId the ID of specified policy type
     *
     * @return the Response object containing the results of the API operation
     */
    @GET
    @Path("/policytypes/{policyTypeId}/versions/latest")
    @ApiOperation(value = "Retrieve latest version of a policy type",
        notes = "Returns latest version for the specified policy type", response = ToscaServiceTemplate.class,
        responseHeaders = {
            @ResponseHeader(name = "X-MinorVersion",
                description = "Used to request or communicate a MINOR version back from the client"
                    + " to the server, and from the server back to the client",
                response = String.class),
            @ResponseHeader(name = "X-PatchVersion",
                description = "Used only to communicate a PATCH version in a response for"
                    + " troubleshooting purposes only, and will not be provided by" + " the client on request",
                response = String.class),
            @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version",
                response = String.class),
            @ResponseHeader(name = "X-ONAP-RequestID",
                description = "Used to track REST transactions for logging purpose", response = UUID.class)},
        authorizations = @Authorization(value = "basicAuth"), tags = {"PolicyType", },
        extensions = {
            @Extension(name = "interface info", properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
                @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
    @ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"),
        @ApiResponse(code = 403, message = "Authorization Error"),
        @ApiResponse(code = 404, message = "Resource Not Found"),
        @ApiResponse(code = 500, message = "Internal Server Error")})
    public Response getLatestVersionOfPolicyType(
        @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
        @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {

        try (PolicyTypeProvider policyTypeProvider = new PolicyTypeProvider()) {
            ToscaServiceTemplate serviceTemplate = policyTypeProvider.fetchLatestPolicyTypes(policyTypeId);
            updateApiStatisticsCounter(Target.POLICY_TYPE, Result.SUCCESS, HttpMethod.GET);
            return makeOkResponse(requestId, serviceTemplate);
        } catch (PfModelException | PfModelRuntimeException pfme) {
            LOGGER.debug("GET /policytypes/{}/versions/latest", policyTypeId, pfme);
            updateApiStatisticsCounter(Target.POLICY_TYPE, Result.FAILURE, HttpMethod.GET);
            return makeErrorResponse(requestId, pfme);
        }
    }

    /**
     * Creates a new policy type.
     *
     * @param body the body of policy type following TOSCA definition
     *
     * @return the Response object containing the results of the API operation
     */
    @POST
    @Path("/policytypes")
    @ApiOperation(value = "Create a new policy type", notes = "Client should provide TOSCA body of the new policy type",
        authorizations = @Authorization(value = "basicAuth"), tags = {"PolicyType", },
        response = ToscaServiceTemplate.class,
        responseHeaders = {
            @ResponseHeader(name = "X-MinorVersion",
                description = "Used to request or communicate a MINOR version back from the client"
                    + " to the server, and from the server back to the client",
                response = String.class),
            @ResponseHeader(name = "X-PatchVersion",
                description = "Used only to communicate a PATCH version in a response for"
                    + " troubleshooting purposes only, and will not be provided by" + " the client on request",
                response = String.class),
            @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version",
                response = String.class),
            @ResponseHeader(name = "X-ONAP-RequestID",
                description = "Used to track REST transactions for logging purpose", response = UUID.class)},
        extensions = {
            @Extension(name = "interface info", properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
                @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
    @ApiResponses(value = {@ApiResponse(code = 400, message = "Invalid Body"),
        @ApiResponse(code = 401, message = "Authentication Error"),
        @ApiResponse(code = 403, message = "Authorization Error"),
        @ApiResponse(code = 406, message = "Not Acceptable Payload"),
        @ApiResponse(code = 500, message = "Internal Server Error")})
    public Response createPolicyType(
        @ApiParam(value = "Entity body of policy type", required = true) ToscaServiceTemplate body,
        @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {

        if (NetLoggerUtil.getNetworkLogger().isInfoEnabled()) {
            NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, "/policytypes", toJson(body));
        }

        try (PolicyTypeProvider policyTypeProvider = new PolicyTypeProvider()) {
            ToscaServiceTemplate serviceTemplate = policyTypeProvider.createPolicyType(body);
            updateApiStatisticsCounter(Target.POLICY_TYPE, Result.SUCCESS, HttpMethod.POST);
            return makeOkResponse(requestId, serviceTemplate);
        } catch (PfModelException | PfModelRuntimeException pfme) {
            LOGGER.debug("POST /policytypes", pfme);
            updateApiStatisticsCounter(Target.POLICY_TYPE, Result.FAILURE, HttpMethod.POST);
            return makeErrorResponse(requestId, pfme);
        }
    }

    /**
     * Deletes specified version of a particular policy type.
     *
     * @param policyTypeId the ID of specified policy type
     * @param versionId the version of specified policy type
     *
     * @return the Response object containing the results of the API operation
     */
    @DELETE
    @Path("/policytypes/{policyTypeId}/versions/{versionId}")
    @ApiOperation(value = "Delete one version of a policy type",
        notes = "Rule 1: pre-defined policy types cannot be deleted;"
            + "Rule 2: policy types that are in use (parameterized by a TOSCA policy) cannot be deleted."
            + "The parameterizing TOSCA policies must be deleted first;",
        authorizations = @Authorization(value = "basicAuth"), tags = {"PolicyType", },
        response = ToscaServiceTemplate.class,
        responseHeaders = {
            @ResponseHeader(name = "X-MinorVersion",
                description = "Used to request or communicate a MINOR version back from the client"
                    + " to the server, and from the server back to the client",
                response = String.class),
            @ResponseHeader(name = "X-PatchVersion",
                description = "Used only to communicate a PATCH version in a response for"
                    + " troubleshooting purposes only, and will not be provided by" + " the client on request",
                response = String.class),
            @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version",
                response = String.class),
            @ResponseHeader(name = "X-ONAP-RequestID",
                description = "Used to track REST transactions for logging purpose", response = UUID.class)},
        extensions = {
            @Extension(name = "interface info", properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
                @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
    @ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"),
        @ApiResponse(code = 403, message = "Authorization Error"),
        @ApiResponse(code = 404, message = "Resource Not Found"),
        @ApiResponse(code = 409, message = "Delete Conflict, Rule Violation"),
        @ApiResponse(code = 500, message = "Internal Server Error")})
    public Response deleteSpecificVersionOfPolicyType(
        @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
        @PathParam("versionId") @ApiParam(value = "Version of policy type", required = true) String versionId,
        @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {

        try (PolicyTypeProvider policyTypeProvider = new PolicyTypeProvider()) {
            ToscaServiceTemplate serviceTemplate = policyTypeProvider.deletePolicyType(policyTypeId, versionId);
            return makeOkResponse(requestId, serviceTemplate);
        } catch (PfModelException | PfModelRuntimeException pfme) {
            LOGGER.debug("DELETE /policytypes/{}/versions/{}", policyTypeId, versionId, pfme);
            return makeErrorResponse(requestId, pfme);
        }
    }

    /**
     * Retrieves all versions of a particular policy.
     *
     * @param policyTypeId the ID of specified policy type
     * @param policyTypeVersion the version of specified policy type
     *
     * @return the Response object containing the results of the API operation
     */
    // @formatter:off
    @GET
    @Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies")
    @ApiOperation(
        value = "Retrieve all versions of a policy created for a particular policy type version",
        notes = "Returns a list of all versions of specified policy created for the specified policy type version",
        response = ToscaServiceTemplate.class,
        responseHeaders = {
            @ResponseHeader(name = "X-MinorVersion",
                description = "Used to request or communicate a MINOR version back from the client"
                    + " to the server, and from the server back to the client",
                response = String.class),
            @ResponseHeader(name = "X-PatchVersion",
                description = "Used only to communicate a PATCH version in a response for"
                    + " troubleshooting purposes only, and will not be provided by" + " the client on request",
                response = String.class),
            @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version",
                response = String.class),
            @ResponseHeader(name = "X-ONAP-RequestID",
                description = "Used to track REST transactions for logging purpose", response = UUID.class)},
        authorizations = @Authorization(value = "basicAuth"), tags = {"Policy,"},
        extensions = {
            @Extension(name = "interface info", properties = {
                @ExtensionProperty(name = "api-version", value = "1.0.0"),
                @ExtensionProperty(name = "last-mod-release", value = "Dublin")
            })
        }
    )
    @ApiResponses(value = {
        @ApiResponse(code = 401, message = "Authentication Error"),
        @ApiResponse(code = 403, message = "Authorization Error"),
        @ApiResponse(code = 404, message = "Resource Not Found"),
        @ApiResponse(code = 500, message = "Internal Server Error")
    })
    public Response getAllPolicies(
        @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
        @PathParam("policyTypeVersion") @ApiParam(value = "Version of policy type",
            required = true) String policyTypeVersion,
        @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId,
        @QueryParam("mode") @DefaultValue("bare") @ApiParam("Fetch mode for policies, BARE for bare policies (default),"
            + " REFERENCED for fully referenced policies") PolicyFetchMode mode
    ) {

        try (PolicyProvider policyProvider = new PolicyProvider()) {
            ToscaServiceTemplate serviceTemplate =
                policyProvider.fetchPolicies(policyTypeId, policyTypeVersion, null, null, mode);
            updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.GET);
            return makeOkResponse(requestId, serviceTemplate);
        } catch (PfModelException | PfModelRuntimeException pfme) {
            LOGGER.debug("GET /policytypes/{}/versions/{}/policies", policyTypeId, policyTypeVersion, pfme);
            updateApiStatisticsCounter(Target.POLICY, Result.FAILURE, HttpMethod.GET);
            return makeErrorResponse(requestId, pfme);
        }
    }
    // @formatter:on

    /**
     * Retrieves all versions of a particular policy.
     *
     * @param policyTypeId the ID of specified policy type
     * @param policyTypeVersion the version of specified policy type
     * @param policyId the ID of specified policy
     *
     * @return the Response object containing the results of the API operation
     */
    // @formatter:off
    @GET
    @Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}")
    @ApiOperation(value = "Retrieve all version details of a policy created for a particular policy type version",
        notes = "Returns a list of all version details of the specified policy", response = ToscaServiceTemplate.class,
        responseHeaders = {
            @ResponseHeader(name = "X-MinorVersion",
                description = "Used to request or communicate a MINOR version back from the client"
                    + " to the server, and from the server back to the client",
                response = String.class),
            @ResponseHeader(name = "X-PatchVersion",
                description = "Used only to communicate a PATCH version in a response for"
                    + " troubleshooting purposes only, and will not be provided by" + " the client on request",
                response = String.class),
            @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version",
                response = String.class),
            @ResponseHeader(name = "X-ONAP-RequestID",
                description = "Used to track REST transactions for logging purpose", response = UUID.class)},
        authorizations = @Authorization(value = "basicAuth"), tags = {"Policy", },
        extensions = {
            @Extension(name = "interface info", properties = {
                @ExtensionProperty(name = "api-version", value = "1.0.0"),
                @ExtensionProperty(name = "last-mod-release", value = "Dublin")
            })
        }
    )
    @ApiResponses(value = {
        @ApiResponse(code = 401, message = "Authentication Error"),
        @ApiResponse(code = 403, message = "Authorization Error"),
        @ApiResponse(code = 404, message = "Resource Not Found"),
        @ApiResponse(code = 500, message = "Internal Server Error")
    })
    public Response getAllVersionsOfPolicy(
        @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
        @PathParam("policyTypeVersion") @ApiParam(value = "Version of policy type",
            required = true) String policyTypeVersion,
        @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
        @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId,
        @QueryParam("mode") @DefaultValue("bare") @ApiParam("Fetch mode for policies, BARE for bare policies (default),"
            + " REFERENCED for fully referenced policies") PolicyFetchMode mode
    ) {
        try (PolicyProvider policyProvider = new PolicyProvider()) {
            ToscaServiceTemplate serviceTemplate =
                policyProvider.fetchPolicies(policyTypeId, policyTypeVersion, policyId, null, mode);
            updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.GET);
            return makeOkResponse(requestId, serviceTemplate);
        } catch (PfModelException | PfModelRuntimeException pfme) {
            LOGGER.debug("/policytypes/{}/versions/{}/policies/{}", policyTypeId, policyTypeVersion, policyId, pfme);
            updateApiStatisticsCounter(Target.POLICY, Result.FAILURE, HttpMethod.GET);
            return makeErrorResponse(requestId, pfme);
        }
    }
    // @formatter:on

    /**
     * Retrieves the specified version of a particular policy.
     *
     * @param policyTypeId the ID of specified policy type
     * @param policyTypeVersion the version of specified policy type
     * @param policyId the ID of specified policy
     * @param policyVersion the version of specified policy
     *
     * @return the Response object containing the results of the API operation
     */
    // @formatter:off
    @GET
    @Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}/versions/{policyVersion}")
    @ApiOperation(value = "Retrieve one version of a policy created for a particular policy type version",
        notes = "Returns a particular version of specified policy created for the specified policy type version",
        response = ToscaServiceTemplate.class,
        responseHeaders = {
            @ResponseHeader(name = "X-MinorVersion",
                description = "Used to request or communicate a MINOR version back from the client"
                    + " to the server, and from the server back to the client",
                response = String.class),
            @ResponseHeader(name = "X-PatchVersion",
                description = "Used only to communicate a PATCH version in a response for"
                    + " troubleshooting purposes only, and will not be provided by" + " the client on request",
                response = String.class),
            @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version",
                response = String.class),
            @ResponseHeader(name = "X-ONAP-RequestID",
                description = "Used to track REST transactions for logging purpose", response = UUID.class)},
        authorizations = @Authorization(value = "basicAuth"), tags = {"Policy", },
        extensions = {
            @Extension(name = "interface info", properties = {
                @ExtensionProperty(name = "api-version", value = "1.0.0"),
                @ExtensionProperty(name = "last-mod-release", value = "Dublin")
            })
        }
    )
    @ApiResponses(value = {
        @ApiResponse(code = 401, message = "Authentication Error"),
        @ApiResponse(code = 403, message = "Authorization Error"),
        @ApiResponse(code = 404, message = "Resource Not Found"),
        @ApiResponse(code = 500, message = "Internal Server Error")
    })
    public Response getSpecificVersionOfPolicy(
        @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
        @PathParam("policyTypeVersion") @ApiParam(value = "Version of policy type",
            required = true) String policyTypeVersion,
        @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
        @PathParam("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,
        @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId,
        @QueryParam("mode") @DefaultValue("bare") @ApiParam("Fetch mode for policies, BARE for bare policies (default),"
            + " REFERENCED for fully referenced policies") PolicyFetchMode mode
    ) {
        try (PolicyProvider policyProvider = new PolicyProvider()) {
            ToscaServiceTemplate serviceTemplate =
                policyProvider.fetchPolicies(policyTypeId, policyTypeVersion, policyId, policyVersion, mode);
            updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.GET);
            return makeOkResponse(requestId, serviceTemplate);
        } catch (PfModelException | PfModelRuntimeException pfme) {
            LOGGER.debug("GET /policytypes/{}/versions/{}/policies/{}/versions/{}", policyTypeId, policyTypeVersion,
                policyId, policyVersion, pfme);
            updateApiStatisticsCounter(Target.POLICY, Result.FAILURE, HttpMethod.GET);
            return makeErrorResponse(requestId, pfme);
        }
    }
    // @formatter:on

    /**
     * Retrieves the latest version of a particular policy.
     *
     * @param policyTypeId the ID of specified policy type
     * @param policyTypeVersion the version of specified policy type
     * @param policyId the ID of specified policy
     *
     * @return the Response object containing the results of the API operation
     */
    @GET
    @Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}/versions/latest")
    @ApiOperation(value = "Retrieve the latest version of a particular policy",
        notes = "Returns the latest version of specified policy", response = ToscaServiceTemplate.class,
        responseHeaders = {
            @ResponseHeader(name = "X-MinorVersion",
                description = "Used to request or communicate a MINOR version back from the client"
                    + " to the server, and from the server back to the client",
                response = String.class),
            @ResponseHeader(name = "X-PatchVersion",
                description = "Used only to communicate a PATCH version in a response for"
                    + " troubleshooting purposes only, and will not be provided by" + " the client on request",
                response = String.class),
            @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version",
                response = String.class),
            @ResponseHeader(name = "X-ONAP-RequestID",
                description = "Used to track REST transactions for logging purpose", response = UUID.class)},
        authorizations = @Authorization(value = "basicAuth"), tags = {"Policy", },
        extensions = {
            @Extension(name = "interface info", properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
                @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
    @ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"),
        @ApiResponse(code = 403, message = "Authorization Error"),
        @ApiResponse(code = 404, message = "Resource Not Found"),
        @ApiResponse(code = 500, message = "Internal Server Error")})
    public Response getLatestVersionOfPolicy(
        @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
        @PathParam("policyTypeVersion") @ApiParam(value = "Version of policy type",
            required = true) String policyTypeVersion,
        @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
        @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId,
        @QueryParam("mode") @ApiParam("Fetch mode for policies, TERSE for bare policies (default), "
            + "REFERENCED for fully referenced policies") PolicyFetchMode mode) {

        try (PolicyProvider policyProvider = new PolicyProvider()) {
            ToscaServiceTemplate serviceTemplate =
                policyProvider.fetchLatestPolicies(policyTypeId, policyTypeVersion, policyId, mode);
            updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.GET);
            return makeOkResponse(requestId, serviceTemplate);
        } catch (PfModelException | PfModelRuntimeException pfme) {
            LOGGER.debug("GET /policytypes/{}/versions/{}/policies/{}/versions/latest", policyTypeId, policyTypeVersion,
                policyId, pfme);
            updateApiStatisticsCounter(Target.POLICY, Result.FAILURE, HttpMethod.GET);
            return makeErrorResponse(requestId, pfme);
        }
    }

    /**
     * Creates a new policy for a particular policy type and version.
     *
     * @param policyTypeId the ID of specified policy type
     * @param policyTypeVersion the version of specified policy type
     * @param body the body of policy following TOSCA definition
     *
     * @return the Response object containing the results of the API operation
     */
    @POST
    @Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies")
    @ApiOperation(value = "Create a new policy for a policy type version",
        notes = "Client should provide TOSCA body of the new policy",
        authorizations = @Authorization(value = "basicAuth"), tags = {"Policy", },
            response = ToscaServiceTemplate.class,
        responseHeaders = {
            @ResponseHeader(name = "X-MinorVersion",
                description = "Used to request or communicate a MINOR version back from the client"
                    + " to the server, and from the server back to the client",
                response = String.class),
            @ResponseHeader(name = "X-PatchVersion",
                description = "Used only to communicate a PATCH version in a response for"
                    + " troubleshooting purposes only, and will not be provided by" + " the client on request",
                response = String.class),
            @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version",
                response = String.class),
            @ResponseHeader(name = "X-ONAP-RequestID",
                description = "Used to track REST transactions for logging purpose", response = UUID.class)},
        extensions = {
            @Extension(name = "interface info", properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
                @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
    @ApiResponses(value = {@ApiResponse(code = 400, message = "Invalid Body"),
        @ApiResponse(code = 401, message = "Authentication Error"),
        @ApiResponse(code = 403, message = "Authorization Error"),
        @ApiResponse(code = 404, message = "Resource Not Found"),
        @ApiResponse(code = 406, message = "Not Acceptable Payload"),
        @ApiResponse(code = 500, message = "Internal Server Error")})
    public Response createPolicy(
        @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
        @PathParam("policyTypeVersion") @ApiParam(value = "Version of policy type",
            required = true) String policyTypeVersion,
        @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId,
        @ApiParam(value = "Entity body of policy", required = true) ToscaServiceTemplate body) {

        if (NetLoggerUtil.getNetworkLogger().isInfoEnabled()) {
            NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST,
                "/policytypes/" + policyTypeId + "/versions/" + policyTypeVersion + "/policies", toJson(body));
        }

        try (PolicyProvider policyProvider = new PolicyProvider()) {
            ToscaServiceTemplate serviceTemplate = policyProvider.createPolicy(policyTypeId, policyTypeVersion, body);
            updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.POST);
            return makeOkResponse(requestId, serviceTemplate);
        } catch (PfModelException | PfModelRuntimeException pfme) {
            LOGGER.debug("POST /policytypes/{}/versions/{}/policies", policyTypeId, policyTypeVersion, pfme);
            updateApiStatisticsCounter(Target.POLICY, Result.FAILURE, HttpMethod.POST);
            return makeErrorResponse(requestId, pfme);
        }
    }

    /**
     * Creates one or more new policies in one call.
     *
     * @param body the body of policy following TOSCA definition
     *
     * @return the Response object containing the results of the API operation
     */
    @POST
    @Path("/policies")
    @ApiOperation(value = "Create one or more new policies",
        notes = "Client should provide TOSCA body of the new polic(ies)",
        authorizations = @Authorization(value = "basicAuth"), tags = {"Policy", },
            response = ToscaServiceTemplate.class,
        responseHeaders = {
            @ResponseHeader(name = "X-MinorVersion",
                description = "Used to request or communicate a MINOR version back from the client"
                    + " to the server, and from the server back to the client",
                response = String.class),
            @ResponseHeader(name = "X-PatchVersion",
                description = "Used only to communicate a PATCH version in a response for"
                    + " troubleshooting purposes only, and will not be provided by" + " the client on request",
                response = String.class),
            @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version",
                response = String.class),
            @ResponseHeader(name = "X-ONAP-RequestID",
                description = "Used to track REST transactions for logging purpose", response = UUID.class)},
        extensions = {
            @Extension(name = "interface info", properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
                @ExtensionProperty(name = "last-mod-release", value = "El Alto")})})
    @ApiResponses(value = {@ApiResponse(code = 400, message = "Invalid Body"),
        @ApiResponse(code = 401, message = "Authentication Error"),
        @ApiResponse(code = 403, message = "Authorization Error"),
        @ApiResponse(code = 404, message = "Resource Not Found"),
        @ApiResponse(code = 406, message = "Not Acceptable Payload"),
        @ApiResponse(code = 500, message = "Internal Server Error")})
    public Response createPolicies(
        @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId,
        @ApiParam(value = "Entity body of policy", required = true) ToscaServiceTemplate body) {

        if (NetLoggerUtil.getNetworkLogger().isInfoEnabled()) {
            NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, "/policies", toJson(body));
        }

        try (PolicyProvider policyProvider = new PolicyProvider()) {
            ToscaServiceTemplate serviceTemplate = policyProvider.createPolicies(body);
            updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.POST);
            return makeOkResponse(requestId, serviceTemplate);
        } catch (PfModelException | PfModelRuntimeException pfme) {
            LOGGER.debug("POST /policies", pfme);
            updateApiStatisticsCounter(Target.POLICY, Result.FAILURE, HttpMethod.POST);
            return makeErrorResponse(requestId, pfme);
        }
    }

    /**
     * Deletes the specified version of a particular policy.
     *
     * @param policyTypeId the ID of specified policy type
     * @param policyTypeVersion the version of specified policy type
     * @param policyId the ID of specified policy
     * @param policyVersion the version of specified policy
     *
     * @return the Response object containing the results of the API operation
     */
    @DELETE
    @Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}/versions/{policyVersion}")
    @ApiOperation(value = "Delete a particular version of a policy",
        notes = "Rule: the version that has been deployed in PDP group(s) cannot be deleted",
        authorizations = @Authorization(value = "basicAuth"), tags = {"Policy", },
            response = ToscaServiceTemplate.class,
        responseHeaders = {
            @ResponseHeader(name = "X-MinorVersion",
                description = "Used to request or communicate a MINOR version back from the client"
                    + " to the server, and from the server back to the client",
                response = String.class),
            @ResponseHeader(name = "X-PatchVersion",
                description = "Used only to communicate a PATCH version in a response for"
                    + " troubleshooting purposes only, and will not be provided by" + " the client on request",
                response = String.class),
            @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version",
                response = String.class),
            @ResponseHeader(name = "X-ONAP-RequestID",
                description = "Used to track REST transactions for logging purpose", response = UUID.class)},
        extensions = {
            @Extension(name = "interface info", properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
                @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
    @ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"),
        @ApiResponse(code = 403, message = "Authorization Error"),
        @ApiResponse(code = 404, message = "Resource Not Found"),
        @ApiResponse(code = 409, message = "Delete Conflict, Rule Violation"),
        @ApiResponse(code = 500, message = "Internal Server Error")})
    public Response deleteSpecificVersionOfPolicy(
        @PathParam("policyTypeId") @ApiParam(value = "PolicyType ID", required = true) String policyTypeId,
        @PathParam("policyTypeVersion") @ApiParam(value = "Version of policy type",
            required = true) String policyTypeVersion,
        @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
        @PathParam("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,
        @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {

        try (PolicyProvider policyProvider = new PolicyProvider()) {
            ToscaServiceTemplate serviceTemplate =
                policyProvider.deletePolicy(policyTypeId, policyTypeVersion, policyId, policyVersion);
            return makeOkResponse(requestId, serviceTemplate);
        } catch (PfModelException | PfModelRuntimeException pfme) {
            LOGGER.debug("DELETE /policytypes/{}/versions/{}/policies/{}/versions/{}", policyTypeId, policyTypeVersion,
                policyId, policyVersion, pfme);
            return makeErrorResponse(requestId, pfme);
        }
    }

    private enum Target {
        POLICY,
        POLICY_TYPE,
        OTHER
    }

    private enum Result {
        SUCCESS,
        FAILURE
    }

    private enum HttpMethod {
        POST,
        GET
    }

    private void updateApiStatisticsCounter(Target target, Result result, HttpMethod http) {

        ApiStatisticsManager.updateTotalApiCallCount();

        switch (target) {
            case POLICY:
                updatePolicyStats(result, http);
                break;
            case POLICY_TYPE:
                updatePolicyTypeStats(result, http);
                break;
            default:
                ApiStatisticsManager.updateApiCallSuccessCount();
                break;
        }
    }

    private void updatePolicyStats(Result result, HttpMethod http) {
        if (result == Result.SUCCESS) {
            if (http == HttpMethod.GET) {
                ApiStatisticsManager.updateApiCallSuccessCount();
                ApiStatisticsManager.updateTotalPolicyGetCount();
                ApiStatisticsManager.updatePolicyGetSuccessCount();
            } else if (http == HttpMethod.POST) {
                ApiStatisticsManager.updateApiCallSuccessCount();
                ApiStatisticsManager.updateTotalPolicyPostCount();
                ApiStatisticsManager.updatePolicyPostSuccessCount();
            }
        } else {
            if (http == HttpMethod.GET) {
                ApiStatisticsManager.updateApiCallFailureCount();
                ApiStatisticsManager.updateTotalPolicyGetCount();
                ApiStatisticsManager.updatePolicyGetFailureCount();
            } else {
                ApiStatisticsManager.updateApiCallFailureCount();
                ApiStatisticsManager.updateTotalPolicyPostCount();
                ApiStatisticsManager.updatePolicyPostFailureCount();
            }
        }
    }

    private void updatePolicyTypeStats(Result result, HttpMethod http) {
        if (result == Result.SUCCESS) {
            if (http == HttpMethod.GET) {
                ApiStatisticsManager.updateApiCallSuccessCount();
                ApiStatisticsManager.updateTotalPolicyTypeGetCount();
                ApiStatisticsManager.updatePolicyTypeGetSuccessCount();
            } else if (http == HttpMethod.POST) {
                ApiStatisticsManager.updateApiCallSuccessCount();
                ApiStatisticsManager.updatePolicyTypePostSuccessCount();
                ApiStatisticsManager.updatePolicyTypePostSuccessCount();
            }
        } else {
            if (http == HttpMethod.GET) {
                ApiStatisticsManager.updateApiCallFailureCount();
                ApiStatisticsManager.updateTotalPolicyTypeGetCount();
                ApiStatisticsManager.updatePolicyTypeGetFailureCount();
            } else {
                ApiStatisticsManager.updateApiCallFailureCount();
                ApiStatisticsManager.updateTotalPolicyTypePostCount();
                ApiStatisticsManager.updatePolicyTypePostFailureCount();
            }
        }
    }
}