extend vnf properties model for cds actors
[policy/models.git] / models-interactions / model-actors / actor.cds / src / main / java / org / onap / policy / controlloop / actor / cds / properties / GrpcOperationPnfProperties.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * Copyright (C) 2022 AT&T Intellectual Property. All rights reserved.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  * ============LICENSE_END=========================================================
17  */
18
19 package org.onap.policy.controlloop.actor.cds.properties;
20
21 import java.util.LinkedHashMap;
22 import java.util.List;
23 import java.util.Map;
24 import lombok.Data;
25 import lombok.EqualsAndHashCode;
26 import org.onap.policy.controlloop.actor.cds.GrpcOperation;
27 import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
28 import org.onap.policy.controlloop.actorserviceprovider.Util;
29
30 /**
31  * GRPC Operation with PNF properties.
32  */
33
34 @Data
35 @EqualsAndHashCode(callSuper = true)
36 public class GrpcOperationPnfProperties extends GrpcOperationProperties {
37
38     // @formatter:off
39     protected static final List<String> PNF_PROPERTY_NAMES = List.of(
40                             OperationProperties.AAI_PNF,
41                             OperationProperties.EVENT_ADDITIONAL_PARAMS,
42                             OperationProperties.OPT_CDS_GRPC_AAI_PROPERTIES);
43     // @formatter:on
44
45     @Override
46     public List<String> getPropertyNames() {
47         return PNF_PROPERTY_NAMES;
48     }
49
50     @Override
51     public Map<String, String> convertToAaiProperties(GrpcOperation operation) {
52         Map<String, String> result = operation.getProperty(OperationProperties.OPT_CDS_GRPC_AAI_PROPERTIES);
53         if (result != null) {
54             return result;
55         }
56
57         Object pnfData = operation.getRequiredProperty(OperationProperties.AAI_PNF, "PNF");
58         Map<String, Object> source = Util.translateToMap(operation.getFullName(), pnfData);
59
60         result = new LinkedHashMap<>();
61
62         for (Map.Entry<String, Object> ent : source.entrySet()) {
63             result.put(AAI_PNF_PREFIX + ent.getKey(), ent.getValue().toString());
64         }
65
66         return result;
67     }
68 }