aboutsummaryrefslogtreecommitdiffstats
path: root/cps-service/src/main/java/org/onap/cps/spi/model/ConditionProperties.java
blob: 5f5e4bc4ae5be9171ab5676bf4df0b3fb859a855 (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
/*
 *  ============LICENSE_START=======================================================
 *  Copyright (C) 2022 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.cps.spi.model;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.validation.Valid;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;

@Setter
@Getter
@EqualsAndHashCode
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class ConditionProperties {
    @JsonProperty("conditionName")
    private String conditionName = "";

    @JsonProperty("conditionParameters")
    @Valid
    private List<Map<String, String>> conditionParameters = Collections.emptyList();
}
.getLogger(__name__) VALID_FILTERS = ["operationTypes", "operationStates", "notificationTypes", "vnfInstanceId"] def get_problem_details_serializer(status_code, error_message): problem_details = { "status": status_code, "detail": error_message } problem_details_serializer = ProblemDetailsSerializer(data=problem_details) problem_details_serializer.is_valid() return problem_details_serializer class SubscriptionsView(APIView): @swagger_auto_schema( request_body=LccnSubscriptionRequestSerializer(), responses={ status.HTTP_201_CREATED: LccnSubscriptionSerializer(), status.HTTP_303_SEE_OTHER: ProblemDetailsSerializer(), status.HTTP_500_INTERNAL_SERVER_ERROR: ProblemDetailsSerializer() } ) @view_safe_call_with_log(logger=logger) def post(self, request): logger.debug("SubscribeNotification--post::> %s" % request.data) lccn_subscription_request_serializer = LccnSubscriptionRequestSerializer(data=request.data) if not lccn_subscription_request_serializer.is_valid(): raise NFLCMException(lccn_subscription_request_serializer.errors) subscription = CreateSubscription( lccn_subscription_request_serializer.data).do_biz() lccn_notifications_filter = { "notificationTypes": ast.literal_eval(subscription.notification_types), "operationTypes": ast.literal_eval(subscription.operation_types), "operationStates": ast.literal_eval(subscription.operation_states), "vnfInstanceSubscriptionFilter": json.loads(subscription.vnf_instance_filter) } subscription_data = { "id": subscription.subscription_id, "callbackUri": subscription.callback_uri, "_links": json.loads(subscription.links), "filter": lccn_notifications_filter } sub_resp_serializer = LccnSubscriptionSerializer(data=subscription_data) if not sub_resp_serializer.is_valid(): raise NFLCMException(sub_resp_serializer.errors) return Response(data=sub_resp_serializer.data, status=status.HTTP_201_CREATED) @swagger_auto_schema( responses={ status.HTTP_200_OK: LccnSubscriptionsSerializer(), status.HTTP_400_BAD_REQUEST: ProblemDetailsSerializer(), status.HTTP_500_INTERNAL_SERVER_ERROR: ProblemDetailsSerializer() } ) @view_safe_call_with_log(logger=logger) def get(self, request): logger.debug("SubscribeNotification--get::> %s" % request.query_params) if request.query_params and not set(request.query_params).issubset(set(VALID_FILTERS)): problem_details_serializer = get_problem_details_serializer( status.HTTP_400_BAD_REQUEST, "Not a valid filter" ) return Response(data=problem_details_serializer.data, status=status.HTTP_400_BAD_REQUEST) resp_data = QuerySubscription(request.query_params).query_multi_subscriptions() subscriptions_serializer = LccnSubscriptionsSerializer(data=resp_data) if not subscriptions_serializer.is_valid(): raise NFLCMException(subscriptions_serializer.errors) logger.debug("SubscribeNotification--get::> Remove default fields") return Response(data=subscriptions_serializer.data, status=status.HTTP_200_OK)