d80cc9d930bb793e2260aa03a0f3ab1d8c54ed5b
[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 GNBDUFunction extends AbstractFunction {
30
31     @Getter
32     @JsonProperty("attributes")
33     private GNBDUAttributes attributes;
34     @Getter
35     @JsonProperty("_3gpp-nr-nrm-nrcelldu:NRCellDU")
36     private List<NRCellDU> nrCellDUs;
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 gnbduFunctionFdn = "urn:oran:smo:teiv:" + getId();
43
44         for (NRCellDU nrCellDU : getNrCellDUs()) {
45             addNrcellduEntitiesAndRelationships(nrCellDU, entityMap, relationshipMap);
46             addRelationshipWithNrcelldu(nrCellDU, relationshipMap);
47         }
48
49         return Map.of("id", gnbduFunctionFdn, "attributes", attributes.createEntityAttributes(), "sourceIds", List.of(
50                 gnbduFunctionFdn, "urn:oran:smo:teiv:" + parentId));
51     }
52
53     private void addNrcellduEntitiesAndRelationships(NRCellDU nrCellDU, Map<String, List<Object>> entityMap,
54             Map<String, List<Object>> relationshipMap) {
55         String type = "o-ran-smo-teiv-ran:NRCellDU";
56         if (!entityMap.containsKey(type)) {
57             entityMap.put(type, new ArrayList<>());
58         }
59         entityMap.get(type).add(nrCellDU.addTeivEntitiesAndRelationships(entityMap, relationshipMap, getId()));
60     }
61
62     private void addRelationshipWithNrcelldu(NRCellDU nrCellDU, Map<String, List<Object>> relationshipMap) {
63         String relType = "o-ran-smo-teiv-ran:ODUFUNCTION_PROVIDES_NRCELLDU";
64         if (!relationshipMap.containsKey(relType)) {
65             relationshipMap.put(relType, new ArrayList<>());
66         }
67         relationshipMap.get(relType).add(nrCellDU.createRelationshipWithGnbduFunction(getId()));
68     }
69
70     @Override
71     public Map<String, Object> createRelationshipWithManagedElement(String managedElementId) {
72         String gnbduFunctionFdn = "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", gnbduFunctionFdn, "sourceIds", List.of(managedElementFdn, gnbduFunctionFdn));
76     }
77
78     @Override
79     public String getTeivEntityType() {
80         return "o-ran-smo-teiv-ran:ODUFunction";
81     }
82
83     @Override
84     public String getTeivRelationshipWithManagedElement() {
85         return "o-ran-smo-teiv-rel-oam-ran:MANAGEDELEMENT_MANAGES_ODUFUNCTION";
86     }
87
88     @Override
89     public void createRelationshipWithSmo(Map<String, List<Object>> relationshipMap) {
90         String ranFunctionRelType = "o-ran-smo-teiv-ran:ODUFUNCTION_O1LINK_SMO";
91         if (!relationshipMap.containsKey(ranFunctionRelType)) {
92             relationshipMap.put(ranFunctionRelType, new ArrayList<>());
93         }
94         String gnbduFunctionId = getId();
95         String smoId = "SMO";
96         Map<String, Object> test = Map.of("id", String.format("urn:oran:smo:teiv:%s_O1LINK_%s", gnbduFunctionId, smoId),
97                 "bSide", "urn:oran:smo:teiv:" + smoId, "aSide", "urn:oran:smo:teiv:" + gnbduFunctionId, "sourceIds", List
98                         .of(smoId, gnbduFunctionId));
99         relationshipMap.get(ranFunctionRelType).add(test);
100     }
101 }