aboutsummaryrefslogtreecommitdiffstats
path: root/ransim/ransimctrlr/RANSIM-CTRLR/src/main/java/org/onap/ransim/rest/api/services/RANSliceConfigService.java
blob: 36bd48a738e56218dbaca1acc6173701454ba34b (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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
/*
 * ============LICENSE_START=======================================================
 * Ran Simulator Controller
 * ================================================================================
 * Copyright (C) 2020-2021 Wipro Limited.
 * ================================================================================
 * 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.
 * ============LICENSE_END=========================================================
 */

package org.onap.ransim.rest.api.services;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import org.apache.log4j.Logger;
import org.modelmapper.ModelMapper;
import org.modelmapper.convention.MatchingStrategies;
import org.onap.ransim.rest.api.models.GNBCUCPFunction;
import org.onap.ransim.rest.api.models.GNBCUUPFunction;
import org.onap.ransim.rest.api.models.GNBDUFunction;
import org.onap.ransim.rest.api.models.NRCellCU;
import org.onap.ransim.rest.api.models.NRCellDU;
import org.onap.ransim.rest.api.models.NSSAIConfig;
import org.onap.ransim.rest.api.models.NearRTRIC;
import org.onap.ransim.rest.api.models.PLMNInfo;
import org.onap.ransim.rest.api.models.RANSliceInfo;
import org.onap.ransim.rest.api.models.RRMPolicyRatio;
import org.onap.ransim.rest.api.models.SliceProfile;
import org.onap.ransim.rest.api.models.TACells;
import org.onap.ransim.rest.api.repository.GNBCUCPRepository;
import org.onap.ransim.rest.api.repository.GNBCUUPRepository;
import org.onap.ransim.rest.api.repository.GNBDURepository;
import org.onap.ransim.rest.api.repository.NRCellCURepository;
import org.onap.ransim.rest.api.repository.NearRTRICRepository;
import org.onap.ransim.rest.api.repository.RANInventoryRepository;
import org.onap.ransim.rest.api.repository.RRMPolicyRepository;
import org.onap.ransim.rest.api.repository.TACellRepository;
import org.onap.ransim.rest.web.mapper.GNBCUCPModel;
import org.onap.ransim.rest.web.mapper.GNBCUUPModel;
import org.onap.ransim.rest.web.mapper.GNBDUModel;
import org.onap.ransim.rest.web.mapper.NRCellCUModel;
import org.onap.ransim.rest.web.mapper.NRCellDUModel;
import org.onap.ransim.rest.web.mapper.NearRTRICModel;
import org.onap.ransim.rest.web.mapper.RANSliceInfoModel;
import org.onap.ransim.rest.web.mapper.RRMPolicyRatioModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class RANSliceConfigService {
    private static Logger logger = Logger.getLogger(RANSliceConfigService.class.getName());
    @Autowired
    private NRCellCURepository nRCellCURepository;

    @Autowired
    private GNBCUCPRepository gNBCUCPRepository;

    @Autowired
    private GNBCUUPRepository gNBCUUPRepository;

    @Autowired
    private GNBDURepository gNBDURepository;

    @Autowired
    private NearRTRICRepository nearRTRICRepository;

    @Autowired
    private RRMPolicyRepository rRMPolicyRepository;

    @Autowired
    private RANInventoryRepository ranInventoryRepo;

    @Autowired
    private TACellRepository tACellRepository;

    private ModelMapper modelMapper = new ModelMapper();

    /**
     * To store/update the NRCEllCU details
     *
     * @param nRCellCUModel
     * @return NRCellCUModel
     */
    public NRCellCUModel saveNRcellCU(NRCellCUModel nRCellCUModel) {
        logger.debug("Request received to save NRcellCU: id::" + nRCellCUModel.getCellLocalId());
        NRCellCU cellCUEntity = new NRCellCU();
        modelMapper.map(nRCellCUModel, cellCUEntity);
        if (!cellCUEntity.getpLMNInfoList().isEmpty()) {
            for (PLMNInfo plmn : cellCUEntity.getpLMNInfoList()) {
                // plmn.setnRCellCU(cellCUEntity);
            }
        }
        NRCellCU cellCUEntityResponse = nRCellCURepository.save(cellCUEntity);
        modelMapper.map(cellCUEntityResponse, nRCellCUModel);
        return nRCellCUModel;
    }

    /**
     * To fetch the NRCellCU details
     *
     * @param cellLocalId
     * @return NRCellCUModel
     */
    public NRCellCUModel fetchNRCellCUDetails(Integer cellLocalId) {
        logger.debug("Request received to fetchNRCellCUDetails: id::" + cellLocalId);
        modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
        NRCellCU cellCUEntity =
                nRCellCURepository.findById(cellLocalId).isPresent() ? nRCellCURepository.findById(cellLocalId).get()
                        : null;
        NRCellCUModel nRCellCUModel = new NRCellCUModel();
        modelMapper.map(cellCUEntity, nRCellCUModel);
        return nRCellCUModel;
    }

    /**
     * To store the slice / config details of GNBCUCPFunction
     * 
     * @param gNBCUCPModel
     * @return
     */
    public GNBCUCPModel saveGNBCUCP(GNBCUCPModel gNBCUCPModel) {
        logger.debug("Request received to save GNBCUCPModel: id::" + gNBCUCPModel.getgNBCUName());
        modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
        GNBCUCPFunction gNBCUCPFunction = new GNBCUCPFunction();
        NearRTRIC nearRTRICRef = new NearRTRIC();
        try {
            modelMapper.map(gNBCUCPModel, gNBCUCPFunction);
            if (gNBCUCPModel.getNearRTRICId() != null
                    && nearRTRICRepository.findById(gNBCUCPModel.getNearRTRICId()).isPresent()) {
                gNBCUCPFunction.setNearRTRIC(nearRTRICRepository.findById(gNBCUCPModel.getNearRTRICId()).get());
            }
            if (gNBCUCPFunction != null && !gNBCUCPFunction.getCellCUList().isEmpty()) {
                gNBCUCPFunction.getCellCUList().forEach(cellCU -> {
                    cellCU.setgNBCUCPFunction(gNBCUCPFunction);
                });
            }
            GNBCUCPFunction gNBCUCPEntity = gNBCUCPRepository.save(gNBCUCPFunction);
            modelMapper.map(gNBCUCPEntity, gNBCUCPModel);
        } catch (Exception e) {
            logger.debug("Error occured during saveGNBCUCP" + e.getMessage());
            return null;
        }
        return gNBCUCPModel;
    }

    /**
     * To fetch the gNBCUCP details
     *
     * @param cucpName
     * @return GNBCUCPModel
     */
    public GNBCUCPModel fetchGNBCUCPData(String cucpName) {
        logger.debug("Request received to fetch GNBCUCPFunction: name::" + cucpName);
        modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
        GNBCUCPFunction gNBCUCPEntity =
                gNBCUCPRepository.findById(cucpName).isPresent() ? gNBCUCPRepository.findById(cucpName).get() : null;
        GNBCUCPModel gNBCUCPModel = new GNBCUCPModel();
        modelMapper.map(gNBCUCPEntity, gNBCUCPModel);
        return gNBCUCPModel;
    }

    /**
     * To store the slice / config details of GNBCUCPFunction
     * 
     * @param gNBCUCPModel
     * @return
     */
    public GNBCUUPModel saveGNBCUUP(GNBCUUPModel gNBCUUPModel) {
        logger.debug("Request received to save GNBCUUPModel: id::" + gNBCUUPModel.getgNBCUUPId());
        modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
        GNBCUUPFunction gNBCUUPFunction = new GNBCUUPFunction();
        modelMapper.map(gNBCUUPModel, gNBCUUPFunction);
        if (gNBCUUPModel.getNearRTRICId() != null
                && nearRTRICRepository.findById(gNBCUUPModel.getNearRTRICId()).isPresent()) {
            gNBCUUPFunction.setNearRTRIC(nearRTRICRepository.findById(gNBCUUPModel.getNearRTRICId()).get());
        }
        if (gNBCUUPFunction != null && !gNBCUUPFunction.getpLMNInfoList().isEmpty()) {
            gNBCUUPFunction.getpLMNInfoList().forEach(plmn -> {
                // plmn.setgNBCUUPFunction(gNBCUUPFunction);
            });
        }
        GNBCUUPFunction gNBCUUPEntity = gNBCUUPRepository.save(gNBCUUPFunction);
        modelMapper.map(gNBCUUPEntity, gNBCUUPModel);
        return gNBCUUPModel;
    }

    /**
     * To fetch the gNBCUUP details
     *
     * @param cucpName
     * @return GNBCUUPModel
     */
    public GNBCUUPModel fetchGNBCUUPData(Integer gNBCUUPId) {
        logger.debug("Request received to fetch GNBCUUPFunction: id::" + gNBCUUPId);
        modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
        GNBCUUPFunction gNBCUUPEntity =
                gNBCUUPRepository.findById(gNBCUUPId).isPresent() ? gNBCUUPRepository.findById(gNBCUUPId).get() : null;
        GNBCUUPModel gNBCUUPModel = new GNBCUUPModel();
        modelMapper.map(gNBCUUPEntity, gNBCUUPModel);
        return gNBCUUPModel;
    }

    /**
     * To store the slice / config details of GNBDUFunction
     * 
     * @param GNBDUModel
     * @return
     */
    public GNBDUModel saveGNBDU(GNBDUModel gNBDUModel) {
        logger.debug("Request received to save GNBDUModel: id::" + gNBDUModel.getgNBDUId());
        modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
        GNBDUFunction gNBDUFunction = new GNBDUFunction();
        NearRTRIC nearRTRICRef = new NearRTRIC();
        modelMapper.map(gNBDUModel, gNBDUFunction);
        if (gNBDUModel.getNearRTRICId() != null
                && nearRTRICRepository.findById(gNBDUModel.getNearRTRICId()).isPresent()) {
            nearRTRICRef = nearRTRICRepository.findById(gNBDUModel.getNearRTRICId()).get();
            gNBDUFunction.setNearRTRIC(nearRTRICRef);
        }
        NearRTRIC nearRTRICRefNew = nearRTRICRef;
        nearRTRICRefNew.setNearRTRICId(gNBDUModel.getNearRTRICId());
        if (gNBDUFunction != null && !gNBDUFunction.getCellDUList().isEmpty()) {
            gNBDUFunction.getCellDUList().forEach(cellDU -> {
                cellDU.setgNBDUFunction(gNBDUFunction);
            });
        }
        GNBDUFunction gNBDUEntity = gNBDURepository.save(gNBDUFunction);
        modelMapper.map(gNBDUEntity, gNBDUModel);
        return gNBDUModel;
    }

    /**
     * To fetch the gNBDU details
     *
     * @param gNBDUId
     * @return GNBDUModel
     */
    public GNBDUModel fetchGNBDUData(Integer gNBDUId) {
        logger.debug("Request received to fetch GNBDUFunction: id::" + gNBDUId);
        modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
        GNBDUFunction gNBDUEntity =
                gNBDURepository.findById(gNBDUId).isPresent() ? gNBDURepository.findById(gNBDUId).get() : null;
        GNBDUModel gNBDUModel = new GNBDUModel();
        modelMapper.map(gNBDUEntity, gNBDUModel);
        return gNBDUModel;
    }

    /**
     * Stored NearRTRIC
     *
     * @param nearRTRIC
     * @return
     */
    public NearRTRICModel saveNearRTRIC(NearRTRICModel nearRTRIC) {
        logger.debug("Request received to store NearRTRIC: id::" + nearRTRIC.getNearRTRICId());
        modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
        NearRTRIC nearRTRICEntity = new NearRTRIC();
        modelMapper.map(nearRTRIC, nearRTRICEntity);
        NearRTRIC nearRTRICEntityEResponse = nearRTRICRepository.save(nearRTRICEntity);
        modelMapper.map(nearRTRICEntityEResponse, nearRTRIC);
        return nearRTRIC;
    }

    /**
     * To fetch the nearRTRIC details
     *
     * @param nearRTRICId
     * @return NearRTRICModel
     */
    public NearRTRICModel fetchNearRTRICData(Integer nearRTRICId) {
        logger.debug("Request received to fetch GNBDUFunction: id::" + nearRTRICId);
        modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
        NearRTRIC nearRTRICEntity =
                nearRTRICRepository.findById(nearRTRICId).isPresent() ? nearRTRICRepository.findById(nearRTRICId).get()
                        : null;
        NearRTRICModel nearRTRICModel = new NearRTRICModel();
        modelMapper.map(nearRTRICEntity, nearRTRICModel);
        return nearRTRICModel;
    }

    /**
     * To retrieve the RRMPolicy of a network function
     *
     * @param resourceType
     * @param resourceID
     * @return
     */
    public RRMPolicyRatioModel fetchRRMPolicyOfNE(String resourceType, String resourceID) {
        logger.debug("Request received to fetch RRMPolicy:" + resourceType + "--" + resourceID);
        modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
        RRMPolicyRatioModel rrmPolicyResponse = new RRMPolicyRatioModel();
        RRMPolicyRatio rrmPolicyEntity = rRMPolicyRepository.findByResourceTypeAndId(resourceType, resourceID);
        modelMapper.map(rrmPolicyEntity, rrmPolicyResponse);
        return rrmPolicyResponse;
    }

    /**
     * To update RRM policy of NF
     *
     * @param rrmPolicy
     * @return
     */
    public RRMPolicyRatioModel updateRRMPolicy(RRMPolicyRatioModel rrmPolicy) {
        logger.debug("Request received to update RRMPolicy:" + rrmPolicy.getRrmPolicyID());
        RRMPolicyRatio rrmPolicyEntity = new RRMPolicyRatio();
        modelMapper.map(rrmPolicy, rrmPolicyEntity);
        rrmPolicyEntity = rRMPolicyRepository.save(rrmPolicyEntity);
        modelMapper.map(rrmPolicyEntity, rrmPolicy);
        return rrmPolicy;
    }

    /**
     * @param trackingArea
     * @return List<NearRTRICModel>
     */
    public List<NearRTRICModel> findRICsInTA(int trackingArea) {
        logger.debug("Request received to find the NearRTRICs in Tracking Area::" + trackingArea);
        modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
        List<NearRTRIC> nearRTRICsList = nearRTRICRepository.getListOfRICsInTrackingArea(trackingArea);
        List<NearRTRICModel> ricModelList = nearRTRICsList.stream()
                .map(ricEntity -> modelMapper.map(ricEntity, NearRTRICModel.class)).collect(Collectors.toList());
        return ricModelList;
    }

    /**
     * @param cellsList
     * @return
     */
    public List<NearRTRICModel> findNearRTRICofCells(List<Integer> cellsList) {
        List<NearRTRIC> ricEntitiesList = new ArrayList<>();
        modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
        List<String> cucpNames = gNBCUCPRepository.findCUCPByCellIds(cellsList);
        cucpNames.forEach(cucpName -> {
            List<NearRTRIC> ricEntities = new ArrayList<>();
            ricEntities = nearRTRICRepository.findNearRTRICByCUCPName(cucpName);
            ricEntitiesList.addAll(ricEntities);
        });
        List<NearRTRICModel> ricModelList = ricEntitiesList.stream()
                .map(ricEntity -> modelMapper.map(ricEntity, NearRTRICModel.class)).collect(Collectors.toList());
        return ricModelList;
    }

    /**
     * To update the RAN Slice details
     *
     * @param rANSliceInfoModel
     * @return RANSliceInfoModel
     */
    public RANSliceInfoModel updateRANInventory(RANSliceInfoModel rANSliceInfoModel) {
        logger.debug("Request received to update inventory for id::" + rANSliceInfoModel.getRanNFNSSIId());
        RANSliceInfo rANSliceInfoEntity = new RANSliceInfo();
        modelMapper.map(rANSliceInfoModel, rANSliceInfoEntity);
        if (ranInventoryRepo.findById(rANSliceInfoModel.getRanNFNSSIId()).isPresent()) {
            RANSliceInfo ranInfo = ranInventoryRepo.findById(rANSliceInfoModel.getRanNFNSSIId()).get();
            List<String> ranNSSIList = ranInfo.getRanNSSIList();
            ranNSSIList.addAll(rANSliceInfoEntity.getRanNSSIList());
            rANSliceInfoEntity.setRanNSSIList(ranNSSIList);

            List<String> nSSAIList = ranInfo.getnSSAIList();
            nSSAIList.addAll(rANSliceInfoEntity.getnSSAIList());
            rANSliceInfoEntity.setnSSAIList(nSSAIList);

            List<SliceProfile> sliceProfilesList = ranInfo.getSliceProfilesList();
            sliceProfilesList.addAll(rANSliceInfoEntity.getSliceProfilesList());
            rANSliceInfoEntity.setSliceProfilesList(sliceProfilesList);
        } else {
            if (!rANSliceInfoEntity.getSliceProfilesList().isEmpty()) {
                for (SliceProfile profile : rANSliceInfoEntity.getSliceProfilesList()) {
                    profile.setrANSliceInventory(rANSliceInfoEntity);
                }
            }
        }
        rANSliceInfoEntity = ranInventoryRepo.save(rANSliceInfoEntity);
        modelMapper.map(rANSliceInfoEntity, rANSliceInfoModel);
        return rANSliceInfoModel;
    }

    /**
     * @param ranNFNSSIId
     * @return RANSliceInfoModel
     */
    public RANSliceInfoModel fetchRANSlice(String ranNFNSSIId) {
        logger.debug("Request received to read inventory details for id::" + ranNFNSSIId);
        modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
        RANSliceInfo ranSliceInfo =
                ranInventoryRepo.findById(ranNFNSSIId).isPresent() ? ranInventoryRepo.findById(ranNFNSSIId).get()
                        : null;
        RANSliceInfoModel rANSliceInfoModel = new RANSliceInfoModel();
        modelMapper.map(ranSliceInfo, rANSliceInfoModel);
        return rANSliceInfoModel;
    }

    /**
     * @param trackingArea
     * @return List<String>
     */
    public List<String> fetchCellsofTA(int trackingArea) {
        logger.debug("Request recieved to fetch the cell details of TA:" + trackingArea);
        modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
        String cells = tACellRepository.findById(trackingArea).isPresent()
                ? tACellRepository.findById(trackingArea).get().getCellsList()
                : null;
        return cells != null ? Arrays.asList(cells.split(",")) : null;

    }

    public Iterable<TACells> fetchAllTA() {
        logger.info("Request recieved to fetch all TA:");
        return tACellRepository.findAll();
    }

    /**
     * @param nearRTRICId
     * @return List<NRCellCUModel>
     */
    public List<NRCellCUModel> fetchCUCellsofRIC(Integer nearRTRICId) {
        logger.debug("Request recieved to fetch the cell (CU) details of nearRTRICId:" + nearRTRICId);
        modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
        List<NRCellCU> cellCUEntities = new ArrayList<NRCellCU>();
        NearRTRIC nearRTRIC =
                nearRTRICRepository.findById(nearRTRICId).isPresent() ? nearRTRICRepository.findById(nearRTRICId).get()
                        : null;
        if (nearRTRIC != null) {
            List<GNBCUCPFunction> cucpFunctions = nearRTRIC.getgNBCUCPList();
            cucpFunctions.forEach(cucpFunction -> {
                List<NRCellCU> cellCUList = new ArrayList<NRCellCU>();
                cellCUList.addAll(cucpFunction.getCellCUList());
                cellCUEntities.addAll(cellCUList);
            });
            List<NRCellCUModel> cuCellModels =
                    cellCUEntities.stream().map(cellCUEntity -> modelMapper.map(cellCUEntity, NRCellCUModel.class))
                            .collect(Collectors.toList());
            return cuCellModels;
        }
        return new ArrayList<NRCellCUModel>();
    }

    /**
     * @param trackingArea
     * @return List<NRCellDUModel>
     */
    public Map<Integer, List<NRCellDUModel>> fetchDUCellsofRIC(String sNSSAI) {
        logger.debug("Request recieved to fetch the cell (DU) details of sNSSAI:" + sNSSAI);
        modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
        Set<NRCellDU> cellDUEntities = new HashSet<NRCellDU>();
        Set<NRCellDU> cellDUs = new HashSet<NRCellDU>();
        List<NearRTRICModel> ricModels = findRICsByNSSAI(sNSSAI);
        Map<Integer, List<NRCellDUModel>> cellsMap = new HashMap<Integer, List<NRCellDUModel>>();
        List<NearRTRIC> ricEntities =
                ricModels.stream().map(ric -> modelMapper.map(ric, NearRTRIC.class)).collect(Collectors.toList());
        ricEntities.forEach(ricEntity -> {
            List<GNBDUFunction> duFunctions = ricEntity.getgNBDUList();
            duFunctions.forEach(duFunction -> {
                List<NRCellDU> cellDUList = duFunction.getCellDUList();
                cellDUList.forEach(cellDU -> {
                    List<PLMNInfo> plmnList = cellDU.getpLMNInfoList();
                    plmnList.forEach(plmn -> {
                        if (sNSSAI.equalsIgnoreCase(plmn.getsNSSAI().getsNSSAI())) {
                            cellDUs.add(cellDU);
                        }
                    });
                });
                // cellDUList.addAll(duFunction.getCellDUList());
                cellDUEntities.addAll(cellDUs);
            });
            List<NRCellDUModel> duCellModels =
                    cellDUEntities.stream().map(cellDUEntity -> modelMapper.map(cellDUEntity, NRCellDUModel.class))
                            .collect(Collectors.toList());
            cellsMap.put(ricEntity.getNearRTRICId(), duCellModels);
        });

        return cellsMap;
    }

    /**
     * @param ranNFNSSIID
     * @return List<NearRTRICModel>
     */
    public List<NearRTRICModel> findNearRTRICByNSSI(String ranNFNSSIID) {
        logger.debug("Request recieved to fetch nearRTRIC of NSSI:" + ranNFNSSIID);
        modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
        List<NearRTRIC> nearRTRICEntities = nearRTRICRepository.findNearRTRICByNSSI(ranNFNSSIID);
        List<NearRTRICModel> nearRTRICModels = nearRTRICEntities.stream()
                .map(nearRTRICEntity -> modelMapper.map(nearRTRICEntity, NearRTRICModel.class))
                .collect(Collectors.toList());
        return nearRTRICModels;
    }

    /**
     * @param sNSSAI
     * @return List<NearRTRICModel>
     */
    public List<NearRTRICModel> findRICsByNSSAI(String sNSSAI) {
        logger.debug("Request recieved to fetch nearRTRIC of NSSAI:" + sNSSAI);
        modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
        Set<NearRTRIC> nearRTRICEntities = nearRTRICRepository.findNearRTRICByNSSAI(sNSSAI);
        List<NearRTRICModel> nearRTRICModels = nearRTRICEntities.stream()
                .map(nearRTRICEntity -> modelMapper.map(nearRTRICEntity, NearRTRICModel.class))
                .collect(Collectors.toList());
        return nearRTRICModels;
    }

    /**
     * @param sNSSAI
     * @return config Details
     */
    public Map<String, Integer> findSliceProfileconfig(String sNSSAI) {
        logger.debug("Request recieved to fetch Config requested for a slice:" + sNSSAI);
        modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
        Map<String, Integer> configDetails = new HashMap<String, Integer>();
        String ranNFNSSIId = ranInventoryRepo.findRANNFNSSIofNSSAI(sNSSAI);
        RANSliceInfo rANSliceInfo =
                ranInventoryRepo.findById(ranNFNSSIId).isPresent() ? ranInventoryRepo.findById(ranNFNSSIId).get()
                        : null;
        if (rANSliceInfo.getSliceProfilesList().size() > 0) {
            rANSliceInfo.getSliceProfilesList().forEach(sliceProfile -> {
                if (sNSSAI.equalsIgnoreCase(sliceProfile.getsNSSAI())) {
                    // configDetails.put("maxNoOfConns",sliceProfile.getMaxNumberofConns());
                    configDetails.put("dLThptPerSlice", sliceProfile.getdLThptPerSlice());
                    configDetails.put("uLThptPerSlice", sliceProfile.getuLThptPerSlice());
                }
            });
        }
        return configDetails;
    }

    /**
     * @param sNSSAI
     * @return RIC Config for a slice
     */
    public Map<Integer, NSSAIConfig> findSliceConfig(String sNSSAI) {
        logger.debug("Request recieved to fetch Slice config Details at RICs:" + sNSSAI);
        modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
        List<NearRTRICModel> nearRTRICModels = findRICsByNSSAI(sNSSAI);
        Map<Integer, NSSAIConfig> configMap = new HashMap<Integer, NSSAIConfig>();
        nearRTRICModels.forEach(nearRTRIC -> {
            nearRTRIC.getpLMNInfoList().forEach(plmn -> {
                if (sNSSAI.equalsIgnoreCase(plmn.getsNSSAI().getsNSSAI())) {
                    configMap.put(nearRTRIC.getNearRTRICId(), plmn.getsNSSAI().getConfigData());
                }
            });
        });
        return configMap;
    }

    /**
     * @param sNSSAI
     * @return List<GNBDUModel>
     */
    public List<GNBDUModel> findDUsofSNssai(String sNSSAI) {
        logger.debug("Request recieved to fetch all DUs of NSSAI");
        modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
        List<GNBDUFunction> duList = (List<GNBDUFunction>) gNBDURepository.findDUsByNSSAI(sNSSAI);
        List<GNBDUModel> duModels = duList.stream().map(duEntity -> modelMapper.map(duEntity, GNBDUModel.class))
                .collect(Collectors.toList());
        return duModels;
    }

    /**
     * @param sNSSAI
     * @return List<GNBCUCPModel>
     */
    public List<GNBCUCPModel> findCUsofSNssai(String sNSSAI) {
        logger.debug("Request recieved to fetch all CUs of NSSAI");
        modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
        List<GNBCUCPFunction> cuList = (List<GNBCUCPFunction>) gNBCUCPRepository.findCUCPsByNSSAI(sNSSAI);
        List<GNBCUCPModel> cuModels = cuList.stream().map(cuEntity -> modelMapper.map(cuEntity, GNBCUCPModel.class))
                .collect(Collectors.toList());
        return cuModels;
    }

    /**
     * @param sNSSAI
     * @return Map<String, String>
     */
    public Map<String, String> getSubscriberDetails(String sNSSAI) {
        logger.debug("Request recieved to fetch SubscriberDetails");
        modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
        Map<String, String> details = new HashMap<String, String>();
        String ranNFNSSIId = ranInventoryRepo.findRANNFNSSIofNSSAI(sNSSAI);
        details.put("ranNFNSSIId", ranNFNSSIId);
        details.put("sNSSAI", sNSSAI);
        RANSliceInfo rANSliceInfo =
                ranInventoryRepo.findById(ranNFNSSIId).isPresent() ? ranInventoryRepo.findById(ranNFNSSIId).get()
                        : null;
        if (rANSliceInfo.getSliceProfilesList().size() > 0) {
            rANSliceInfo.getSliceProfilesList().forEach(sliceProfile -> {
                if (sNSSAI.equalsIgnoreCase(sliceProfile.getsNSSAI())) {
                    details.put("sliceProfileId", sliceProfile.getSliceProfileId());
                }
            });
        }
        List<NearRTRICModel> nearRTRICModels = findRICsByNSSAI(sNSSAI);
        nearRTRICModels.forEach(nearRTRIC -> {
            nearRTRIC.getpLMNInfoList().forEach(plmn -> {
                if (sNSSAI.equalsIgnoreCase(plmn.getsNSSAI().getsNSSAI())) {
                    details.put("subscriptionServiceType", plmn.getsNSSAI().getSubscriptionServiceType());
                    details.put("globalSubscriberId", plmn.getsNSSAI().getGlobalSubscriberId());
                }
            });
        });

        return details;
    }

    // Data required for PM data Simulation
    /**
     * @return List<GNBCUCPModel>
     */
    public List<GNBCUCPModel> findAllCUCPFunctions() {
        logger.debug("Request recieved to fetch all CUCPs");
        modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
        List<GNBCUCPFunction> cucpsList = (List<GNBCUCPFunction>) gNBCUCPRepository.findAll();
        List<GNBCUCPModel> cucpModels = cucpsList.stream()
                .map(cucpEntity -> modelMapper.map(cucpEntity, GNBCUCPModel.class)).collect(Collectors.toList());
        return cucpModels;
    }

    /**
     * @return List<GNBDUModel>
     */
    public List<GNBDUModel> findAllDUFunctions() {
        logger.debug("Request recieved to fetch all DUs");
        modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
        List<GNBDUFunction> duList = (List<GNBDUFunction>) gNBDURepository.findAll();
        List<GNBDUModel> duModels = duList.stream().map(duEntity -> {
            GNBDUModel gnbDuModel = modelMapper.map(duEntity, GNBDUModel.class);
            gnbDuModel.setNearRTRICId(duEntity.getNearRTRIC().getNearRTRICId());
            return gnbDuModel;
        }).collect(Collectors.toList());
        return duModels;
    }

    public List<NearRTRICModel> findAllNearRTRIC() {
        logger.debug("Request received to fetch all NearRTRICModel");
        modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
        List<NearRTRIC> rtricList = (List<NearRTRIC>) nearRTRICRepository.findAll();
        List<NearRTRICModel> rtricmodels = rtricList.stream()
                .map(rtricEntity -> modelMapper.map(rtricEntity, NearRTRICModel.class)).collect(Collectors.toList());
        return rtricmodels;
    }

}