2 * ========================LICENSE_START=================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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===================================
21 package org.onap.ccsdk.oran.a1policymanagementservice.controllers.v3;
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.service.v3.ErrorHandlingService;
32 import org.onap.ccsdk.oran.a1policymanagementservice.service.v3.PolicyService;
33 import org.springframework.http.ResponseEntity;
34 import org.springframework.web.bind.annotation.RequestMapping;
35 import org.springframework.web.bind.annotation.RestController;
36 import org.springframework.web.server.ServerWebExchange;
37 import reactor.core.publisher.Flux;
38 import reactor.core.publisher.Mono;
39 @RestController("policyControllerV3")
40 @RequiredArgsConstructor
42 name = PolicyController.API_NAME, //
43 description = PolicyController.API_DESCRIPTION //
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";
50 private final PolicyService policyService;
51 private final ErrorHandlingService errorHandlingService;
54 public Mono<ResponseEntity<PolicyObjectInformation>> createPolicy(Mono<PolicyObjectInformation> policyObjectInformation, ServerWebExchange exchange) {
55 return policyObjectInformation.flatMap(policyObjectInfo -> policyService.createPolicyService(policyObjectInfo, exchange)
56 .doOnError(errorHandlingService::handleError));
60 public Mono<ResponseEntity<Void>> deletePolicy(String policyId, String accept, ServerWebExchange exchange) throws Exception {
61 return policyService.deletePolicyService(policyId, exchange)
62 .doOnError(errorHandlingService::handleError);
66 public Mono<ResponseEntity<Object>> getPolicy(String policyId, String accept, ServerWebExchange exchange) throws Exception {
67 return policyService.getPolicyService(policyId, exchange)
68 .doOnError(errorHandlingService::handleError);
72 public Mono<ResponseEntity<Flux<PolicyInformation>>> getAllPolicies(String policyTypeId, String nearRtRicId, String serviceId, String typeName, String accept, ServerWebExchange exchange) throws Exception {
73 return policyService.getPolicyIdsService(policyTypeId, nearRtRicId, serviceId, typeName, exchange)
74 .doOnError(errorHandlingService::handleError);
78 public Mono<ResponseEntity<Object>> getPolicyTypeDefinition(String policyTypeId, String accept, ServerWebExchange exchange) throws Exception {
79 return policyService.getPolicyTypeDefinitionService(policyTypeId)
80 .doOnError(errorHandlingService::handleError);
84 public Mono<ResponseEntity<Flux<PolicyTypeInformation>>> getPolicyTypes(String nearRtRicId, String typeName, String compatibleWithVersion, String accept, ServerWebExchange exchange) throws Exception {
85 return policyService.getPolicyTypesService(nearRtRicId, typeName, compatibleWithVersion)
86 .doOnError(errorHandlingService::handleError);
90 public Mono<ResponseEntity<Object>> putPolicy(String policyId, Mono<Object> body, ServerWebExchange exchange) throws Exception {
91 return body.flatMap(payload -> policyService.putPolicyService(policyId, payload, exchange))
92 .doOnError(errorHandlingService::handleError);