5034f84f9349d9778788b22852c9f5ed1c36c2c0
[ccsdk/oran.git] /
1 /*-
2  * ========================LICENSE_START=================================
3  * ONAP : ccsdk oran
4  * ======================================================================
5  * Copyright (C) 2024-2025 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 lombok.RequiredArgsConstructor;
25 import org.onap.ccsdk.oran.a1policymanagementservice.controllers.api.v3.A1PolicyManagementApi;
26 import org.onap.ccsdk.oran.a1policymanagementservice.controllers.v2.Consts;
27 import org.onap.ccsdk.oran.a1policymanagementservice.controllers.v2.PolicyController;
28 import org.onap.ccsdk.oran.a1policymanagementservice.models.v3.PolicyInformation;
29 import org.onap.ccsdk.oran.a1policymanagementservice.models.v3.PolicyObjectInformation;
30 import org.onap.ccsdk.oran.a1policymanagementservice.models.v3.PolicyTypeInformation;
31 import org.onap.ccsdk.oran.a1policymanagementservice.models.v3.PolicyTypeObject;
32 import org.onap.ccsdk.oran.a1policymanagementservice.service.v3.ErrorHandlingService;
33 import org.onap.ccsdk.oran.a1policymanagementservice.service.v3.PolicyService;
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 @RequiredArgsConstructor
42 @Tag(//
43         name = PolicyController.API_NAME, //
44         description = PolicyController.API_DESCRIPTION //
45 )
46 @RequestMapping(Consts.V3_API_ROOT)
47 public class PolicyControllerV3 implements A1PolicyManagementApi {
48     public static final String API_NAME = "A1 Policy Management";
49     public static final String API_DESCRIPTION = "API to create,update and get policies or policy definitions";
50
51     private final PolicyService policyService;
52     private final ErrorHandlingService errorHandlingService;
53
54     @Override
55     public Mono<ResponseEntity<PolicyObjectInformation>> createPolicy(Mono<PolicyObjectInformation> policyObjectInformation, ServerWebExchange exchange) {
56         return policyObjectInformation.flatMap(policyObjectInfo -> policyService.createPolicyService(policyObjectInfo, exchange)
57                         .doOnError(errorHandlingService::handleError));
58     }
59
60     @Override
61     public Mono<ResponseEntity<Void>> deletePolicy(String policyId, String accept, ServerWebExchange exchange) throws Exception {
62         return policyService.deletePolicyService(policyId, exchange)
63                 .doOnError(errorHandlingService::handleError);
64     }
65
66     @Override
67     public Mono<ResponseEntity<Object>> getPolicy(String policyId, String accept, ServerWebExchange exchange) throws Exception {
68         return policyService.getPolicyService(policyId, exchange)
69                 .doOnError(errorHandlingService::handleError);
70     }
71
72     @Override
73     public Mono<ResponseEntity<Flux<PolicyInformation>>> getAllPolicies(String policyTypeId, String nearRtRicId, String serviceId, String typeName, String accept, ServerWebExchange exchange) throws Exception {
74         return policyService.getPolicyIdsService(policyTypeId, nearRtRicId, serviceId, typeName, exchange)
75                 .doOnError(errorHandlingService::handleError);
76     }
77
78     @Override
79     public Mono<ResponseEntity<PolicyTypeObject>> getPolicyTypeDefinition(String policyTypeId, String accept, ServerWebExchange exchange) throws Exception {
80         return policyService.getPolicyTypeDefinitionService(policyTypeId)
81                 .doOnError(errorHandlingService::handleError);
82     }
83
84     @Override
85     public Mono<ResponseEntity<Flux<PolicyTypeInformation>>> getPolicyTypes(String nearRtRicId, String typeName, String compatibleWithVersion, String accept, ServerWebExchange exchange) throws Exception {
86         return policyService.getPolicyTypesService(nearRtRicId, typeName, compatibleWithVersion)
87                 .doOnError(errorHandlingService::handleError);
88     }
89
90     @Override
91     public Mono<ResponseEntity<Object>> putPolicy(String policyId, Mono<Object> body, ServerWebExchange exchange) throws Exception {
92         return body.flatMap(payload -> policyService.putPolicyService(policyId, payload, exchange))
93                 .doOnError(errorHandlingService::handleError);
94     }
95
96     @Override
97     public Mono<ResponseEntity<Object>> getPolicyStatus(String policyId, String accept, ServerWebExchange exchange) throws Exception {
98         return policyService.getPolicyStatus(policyId, exchange)
99                 .doOnError(errorHandlingService::handleError);
100     }
101 }