2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.sdnc.northbound.util;
24 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.NetworkTopologyOperationInputBuilder;
25 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.NetworkTopologyOperationOutputBuilder;
26 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.ServiceTopologyOperationInputBuilder;
27 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.ServiceTopologyOperationOutputBuilder;
28 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.network.information.NetworkInformationBuilder;
29 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.network.response.information.NetworkResponseInformationBuilder;
30 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.request.information.RequestInformationBuilder;
31 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.sdnc.request.header.SdncRequestHeaderBuilder;
32 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.service.data.ServiceDataBuilder;
33 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.service.information.ServiceInformationBuilder;
34 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.service.level.oper.status.ServiceLevelOperStatusBuilder;
35 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.service.model.infrastructure.ServiceBuilder;
36 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.service.response.information.ServiceResponseInformationBuilder;
37 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.service.status.ServiceStatusBuilder;
38 import org.opendaylight.yangtools.concepts.Builder;
39 import org.opendaylight.yangtools.yang.common.RpcResult;
41 import java.util.concurrent.Future;
42 import java.util.function.Consumer;
43 import java.util.function.Function;
47 * This uill class provides utility to build yang objects using a recursive syntax that resembles the tree structure
48 * when defining the same yang object in json format.
53 * import static org.onap.sdnc.northbound.util.MDSALUtil.*;
54 * ServiceTopologyOperationInput input = build(
55 * serviceTopologyOperationInput()
56 * .setSdncRequestHeader(build(sdncRequestHeader()
57 * .setSvcRequestId("svc-request-id: xyz")
58 * .setSvcAction(SvcAction.Assign)
60 * .setRequestInformation(build(requestInformation()
61 * .setRequestId("request-id: xyz")
62 * .setRequestAction(RequestInformation.RequestAction.CreateServiceInstance)
64 * .setServiceInformation(build(serviceInformationBuilder()
65 * .setServiceInstanceId("service-instance-id: xyz")
71 public class MDSALUtil {
73 public static ServiceTopologyOperationInputBuilder serviceTopologyOperationInput() {
74 return new ServiceTopologyOperationInputBuilder();
78 public static ServiceTopologyOperationOutputBuilder serviceTopologyOperationOutput(){
79 return new ServiceTopologyOperationOutputBuilder();
83 public static SdncRequestHeaderBuilder sdncRequestHeader() {
84 return new SdncRequestHeaderBuilder();
88 public static RequestInformationBuilder requestInformation() {
89 return new RequestInformationBuilder();
92 public static ServiceResponseInformationBuilder serviceResponseInformation(){
93 return new ServiceResponseInformationBuilder();
96 public static ServiceInformationBuilder serviceInformationBuilder() {
97 return new ServiceInformationBuilder();
101 public static ServiceBuilder service(){return new ServiceBuilder();}
104 public static ServiceDataBuilder serviceData(){return new ServiceDataBuilder();}
107 public static ServiceStatusBuilder serviceStatus(){return new ServiceStatusBuilder();}
109 public static NetworkInformationBuilder networkInformation(){return new NetworkInformationBuilder();}
111 public static NetworkTopologyOperationInputBuilder networkTopologyOperationInput() {return new NetworkTopologyOperationInputBuilder();}
113 public static NetworkTopologyOperationOutputBuilder networkTopologyOperationOutput() {return new NetworkTopologyOperationOutputBuilder();}
115 public static NetworkResponseInformationBuilder networkResponseInformation(){return new NetworkResponseInformationBuilder();}
117 public static ServiceLevelOperStatusBuilder serviceLevelOperStatus() {return new ServiceLevelOperStatusBuilder();}
119 public static <P> P build(Builder<P> b) {
120 return b == null? null :b.build();
123 public static <P,B extends Builder<P>> P build(Function<P,B> builderConstructor,P sourceDataObject){
124 if(sourceDataObject == null){
127 B bp = builderConstructor.apply(sourceDataObject);
131 public static <P,B extends Builder<P>> P build(Function<P,B> builderConstructor,P sourceDataObject,Consumer<B> builder){
132 if(sourceDataObject == null){
135 B bp = builderConstructor.apply(sourceDataObject);
140 public static <I,O> O exec(Function<I,Future<RpcResult<O>>> rpc,I rpcParameter,Function<RpcResult<O>,O> rpcResult) throws Exception {
141 Future<RpcResult<O>> future = rpc.apply(rpcParameter);
142 return rpcResult.apply(future.get());