blob: 68e39787642201f4aa3366696852187926755b53 [file] [log] [blame]
hirokif4ed5212018-05-26 22:39:38 -07001/*
2 * Copyright 2018-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.onosproject.odtn.utils.tapi;
18
19import java.util.Collections;
20import java.util.List;
21import java.util.stream.Collectors;
hirokid8fd7862018-10-09 15:24:24 +090022import org.onosproject.yang.gen.v1.tapicommon.rev20181016.tapicommon.DefaultContext;
23import org.onosproject.yang.gen.v1.tapicommon.rev20181016.tapicommon.Uuid;
24import org.onosproject.yang.gen.v1.tapiconnectivity.rev20181016.tapiconnectivity.connectivitycontext.DefaultConnectivityService;
25import org.onosproject.yang.gen.v1.tapiconnectivity.rev20181016.tapiconnectivity.context.DefaultAugmentedTapiCommonContext;
26import org.onosproject.yang.gen.v1.tapitopology.rev20181016.tapitopology.topologycontext.DefaultTopology;
hirokif4ed5212018-05-26 22:39:38 -070027import org.onosproject.yang.model.DefaultModelObjectData;
28import org.onosproject.yang.model.ModelObjectData;
29import org.onosproject.yang.model.ModelObjectId;
30
31/**
32 * Utility class to deal with TAPI Context with DCS.
33 */
34public final class TapiContextHandler extends TapiObjectHandler<DefaultContext> {
35
36 private TapiContextHandler() {
37 obj = new DefaultContext();
38 }
39
40 public static TapiContextHandler create() {
41 return new TapiContextHandler();
42 }
43
44 @Override
45 protected Uuid getIdDetail() {
hirokid8fd7862018-10-09 15:24:24 +090046 // The target yang object of this class is container, so no need to handle Id.
hirokif4ed5212018-05-26 22:39:38 -070047 return null;
48 }
49
50 @Override
51 protected void setIdDetail(Uuid uuid) {
hirokid8fd7862018-10-09 15:24:24 +090052 // The target yang object of this class is container, so no need to handle Id.
hirokif4ed5212018-05-26 22:39:38 -070053 }
54
55 @Override
56 public ModelObjectId getParentModelObjectId() {
57 return ModelObjectId.builder().build();
58 }
59
60 @Override
61 public ModelObjectData getChildModelObjectData() {
62
63 ModelObjectId mId = ModelObjectId.builder()
64 .addChild(DefaultContext.class)
65 .build();
66
67 DefaultTopology mObj = new DefaultTopology();
68
69 return DefaultModelObjectData.builder()
70 .addModelObject(mObj)
71 .identifier(mId)
72 .build();
73 }
74
75 public List<TapiConnectivityServiceHandler> getConnectivityServices() {
76
77 DefaultAugmentedTapiCommonContext augmentedContext = obj.augmentation(DefaultAugmentedTapiCommonContext.class);
78 try {
hirokid8fd7862018-10-09 15:24:24 +090079 return augmentedContext.connectivityContext().connectivityService().stream()
hirokif4ed5212018-05-26 22:39:38 -070080 .map(connectivityService -> {
81 TapiConnectivityServiceHandler handler = TapiConnectivityServiceHandler.create();
82 handler.setModelObject((DefaultConnectivityService) connectivityService);
83 return handler;
84 }).collect(Collectors.toList());
85 } catch (NullPointerException e) {
86 return Collections.emptyList();
87 }
88 }
89
90}