blob: ff8e24dd3f9f3fccae1c7f9d5e2a3380ef95d0f4 [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;
22import org.onosproject.yang.gen.v1.tapicommon.rev20180307.tapicommon.DefaultContext;
23import org.onosproject.yang.gen.v1.tapicommon.rev20180307.tapicommon.Uuid;
24import org.onosproject.yang.gen.v1.tapiconnectivity.rev20180307.tapiconnectivity.connectivitycontext.DefaultConnectivityService;
25import org.onosproject.yang.gen.v1.tapiconnectivity.rev20180307.tapiconnectivity.context.DefaultAugmentedTapiCommonContext;
26import org.onosproject.yang.gen.v1.tapitopology.rev20180307.tapitopology.topologycontext.DefaultTopology;
27import 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() {
46 return null;
47 }
48
49 @Override
50 protected void setIdDetail(Uuid uuid) {
51 }
52
53 @Override
54 public ModelObjectId getParentModelObjectId() {
55 return ModelObjectId.builder().build();
56 }
57
58 @Override
59 public ModelObjectData getChildModelObjectData() {
60
61 ModelObjectId mId = ModelObjectId.builder()
62 .addChild(DefaultContext.class)
63 .build();
64
65 DefaultTopology mObj = new DefaultTopology();
66
67 return DefaultModelObjectData.builder()
68 .addModelObject(mObj)
69 .identifier(mId)
70 .build();
71 }
72
73 public List<TapiConnectivityServiceHandler> getConnectivityServices() {
74
75 DefaultAugmentedTapiCommonContext augmentedContext = obj.augmentation(DefaultAugmentedTapiCommonContext.class);
76 try {
77 return augmentedContext.connectivityService().stream()
78 .map(connectivityService -> {
79 TapiConnectivityServiceHandler handler = TapiConnectivityServiceHandler.create();
80 handler.setModelObject((DefaultConnectivityService) connectivityService);
81 return handler;
82 }).collect(Collectors.toList());
83 } catch (NullPointerException e) {
84 return Collections.emptyList();
85 }
86 }
87
88}