6c3b9fedf4d601301193db9b50e6e328eae183ae
[smo/teiv.git] /
1 /*
2  *  ============LICENSE_START=======================================================
3  *  Modifications Copyright (C) 2025 OpenInfra Foundation Europe
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  *
17  *  SPDX-License-Identifier: Apache-2.0
18  *  ============LICENSE_END=========================================================
19  */
20 package org.oran.smo.ncmp_to_teiv_adapter.models;
21
22 import com.fasterxml.jackson.annotation.JsonProperty;
23 import lombok.Getter;
24
25 import java.util.ArrayList;
26 import java.util.List;
27 import java.util.Map;
28
29 public class GNBCUCPFunction extends AbstractFunction {
30
31     @Getter
32     @JsonProperty("attributes")
33     private GNBCUCPAttributes attributes;
34     @Getter
35     @JsonProperty("_3gpp-nr-nrm-nrcellcu:NRCellCU")
36     private List<NRCellCU> nrCellCUs;
37
38     @Override
39     public Map<String, Object> addTeivEntitiesAndRelationships(Map<String, List<Object>> entityMap,
40             Map<String, List<Object>> relationshipMap, String parentId) {
41         createRelationshipWithSmo(relationshipMap);
42         String gnbcucpFunctionFdn = "urn:oran:smo:teiv:" + getId();
43
44         for (NRCellCU nrCellCU : getNrCellCUs()) {
45             addNrcellcuEntitiesAndRelationships(nrCellCU, entityMap, relationshipMap);
46             addRelationshipWithNrcellcu(nrCellCU, relationshipMap);
47         }
48
49         return Map.of("id", gnbcucpFunctionFdn, "attributes", attributes.createEntityAttributes(), "sourceIds", List.of(
50                 gnbcucpFunctionFdn, "urn:oran:smo:teiv:" + parentId));
51     }
52
53     private void addNrcellcuEntitiesAndRelationships(NRCellCU nrCellCU, Map<String, List<Object>> entityMap,
54             Map<String, List<Object>> relationshipMap) {
55         String type = "o-ran-smo-teiv-ran:NRCellCU";
56         if (!entityMap.containsKey(type)) {
57             entityMap.put(type, new ArrayList<>());
58         }
59         entityMap.get(type).add(nrCellCU.addTeivEntitiesAndRelationships(entityMap, relationshipMap, getId()));
60     }
61
62     private void addRelationshipWithNrcellcu(NRCellCU nrCellCU, Map<String, List<Object>> relationshipMap) {
63         String relType = "o-ran-smo-teiv-ran:OCUCPFUNCTION_PROVIDES_NRCELLCU";
64         if (!relationshipMap.containsKey(relType)) {
65             relationshipMap.put(relType, new ArrayList<>());
66         }
67         relationshipMap.get(relType).add(nrCellCU.createRelationshipWithGnbcucpFunction(getId()));
68     }
69
70     @Override
71     public Map<String, Object> createRelationshipWithManagedElement(String managedElementId) {
72         String gnbcucpFunctionFdn = "urn:oran:smo:teiv:" + getId();
73         String managedElementFdn = "urn:oran:smo:teiv:" + managedElementId;
74         return Map.of("id", String.format("urn:oran:smo:teiv:%s_MANAGES_%s", managedElementId, getId()), "aSide",
75             managedElementFdn, "bSide", gnbcucpFunctionFdn, "sourceIds", List.of(managedElementFdn, gnbcucpFunctionFdn));
76     }
77
78     @Override
79     public String getTeivEntityType() {
80         return "o-ran-smo-teiv-ran:OCUCPFunction";
81     }
82
83     @Override
84     public String getTeivRelationshipWithManagedElement() {
85         return "o-ran-smo-teiv-rel-oam-ran:MANAGEDELEMENT_MANAGES_OCUCPFUNCTION";
86     }
87
88     @Override
89     public void createRelationshipWithSmo(Map<String, List<Object>> relationshipMap) {
90         String ranFunctionRelType = "o-ran-smo-teiv-ran:OCUCPFUNCTION_O1LINK_SMO";
91         if (!relationshipMap.containsKey(ranFunctionRelType)) {
92             relationshipMap.put(ranFunctionRelType, new ArrayList<>());
93         }
94         String gnbcucpFunctionId = getId();
95         String smoId = "SMO";
96         Map<String, Object> test = Map.of("id", String.format("urn:oran:smo:teiv:%s_O1LINK_%s", gnbcucpFunctionId, smoId),
97                 "bSide", "urn:oran:smo:teiv:" + smoId, "aSide", "urn:oran:smo:teiv:" + gnbcucpFunctionId, "sourceIds", List
98                         .of(smoId, gnbcucpFunctionId));
99         relationshipMap.get(ranFunctionRelType).add(test);
100     }
101 }