4d9f327753b51ac632e3c4ae3a0795618937d4cd
[ccsdk/oran.git] /
1 /*-
2  * ========================LICENSE_START=================================
3  * ONAP : ccsdk oran
4  * ======================================================================
5  * Copyright (C) 2024 OpenInfra Foundation Europe. 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  * ========================LICENSE_END===================================
19  */
20
21 package org.onap.ccsdk.oran.a1policymanagementservice.controllers.v3;
22
23 import io.swagger.v3.oas.annotations.tags.Tag;
24 import org.onap.ccsdk.oran.a1policymanagementservice.controllers.api.v3.A1PolicyManagementApi;
25 import org.onap.ccsdk.oran.a1policymanagementservice.controllers.v2.Consts;
26 import org.onap.ccsdk.oran.a1policymanagementservice.controllers.v2.PolicyController;
27 import org.onap.ccsdk.oran.a1policymanagementservice.models.v3.PolicyInformation;
28 import org.onap.ccsdk.oran.a1policymanagementservice.models.v3.PolicyObjectInformation;
29 import org.onap.ccsdk.oran.a1policymanagementservice.models.v3.PolicyTypeInformation;
30 import org.onap.ccsdk.oran.a1policymanagementservice.service.v3.ErrorHandlingService;
31 import org.onap.ccsdk.oran.a1policymanagementservice.service.v3.PolicyService;
32 import org.onap.ccsdk.oran.a1policymanagementservice.util.v3.Helper;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import org.springframework.http.ResponseEntity;
35 import org.springframework.web.bind.annotation.RequestMapping;
36 import org.springframework.web.bind.annotation.RestController;
37 import org.springframework.web.server.ServerWebExchange;
38 import reactor.core.publisher.Flux;
39 import reactor.core.publisher.Mono;
40 @RestController("PolicyControllerV3")
41 @Tag(//
42         name = PolicyController.API_NAME, //
43         description = PolicyController.API_DESCRIPTION //
44 )
45 @RequestMapping(Consts.V3_API_ROOT)
46 public class PolicyControllerV3 implements A1PolicyManagementApi {
47     public static final String API_NAME = "A1 Policy Management";
48     public static final String API_DESCRIPTION = "API to create,update and get policies or policy definitions";
49     @Autowired
50     private PolicyService policyService;
51
52     @Autowired
53     private Helper helper;
54
55     @Autowired
56     private ErrorHandlingService errorHandlingService;
57
58     @Override
59     public Mono<ResponseEntity<PolicyObjectInformation>> createPolicy(Mono<PolicyObjectInformation> policyObjectInformation, ServerWebExchange exchange) {
60         return policyObjectInformation.flatMap(policyObjectInfo -> policyService.createPolicyService(policyObjectInfo, exchange)
61                         .doOnError(error -> errorHandlingService.handleError(error)));
62     }
63
64     @Override
65     public Mono<ResponseEntity<Void>> deletePolicy(String policyId, String accept, ServerWebExchange exchange) throws Exception {
66         return policyService.deletePolicyService(policyId, exchange)
67                 .doOnError(error -> errorHandlingService.handleError(error));
68     }
69
70     @Override
71     public Mono<ResponseEntity<Object>> getPolicy(String policyId, String accept, ServerWebExchange exchange) throws Exception {
72         return policyService.getPolicyService(policyId, exchange)
73                 .doOnError(error -> errorHandlingService.handleError(error));
74     }
75
76     @Override
77     public Mono<ResponseEntity<Flux<PolicyInformation>>> getPolicyIds(String policyTypeId, String nearRtRicId, String serviceId, String typeName, String accept, ServerWebExchange exchange) throws Exception {
78         return policyService.getPolicyIdsService(policyTypeId, nearRtRicId, serviceId, typeName, exchange)
79                 .doOnError(error -> errorHandlingService.handleError(error));
80     }
81
82     @Override
83     public Mono<ResponseEntity<Object>> getPolicyTypeDefinition(String policyTypeId, String accept, ServerWebExchange exchange) throws Exception {
84         return policyService.getPolicyTypeDefinitionService(policyTypeId)
85                 .doOnError(error -> errorHandlingService.handleError(error));
86     }
87
88     @Override
89     public Mono<ResponseEntity<Flux<PolicyTypeInformation>>> getPolicyTypes(String nearRtRicId, String typeName, String compatibleWithVersion, String accept, ServerWebExchange exchange) throws Exception {
90         return policyService.getPolicyTypesService(nearRtRicId, typeName, compatibleWithVersion, exchange)
91                 .doOnError(error -> errorHandlingService.handleError(error));
92     }
93
94     @Override
95     public Mono<ResponseEntity<Object>> putPolicy(String policyId, Mono<Object> body, ServerWebExchange exchange) throws Exception {
96         return body.flatMap(payload -> policyService.putPolicyService(policyId, payload, exchange))
97                 .doOnError(error -> errorHandlingService.handleError(error));
98     }
99 }