Fix TAPI Sonar issues
[transportpce.git] / tapi / src / main / java / org / opendaylight / transportpce / tapi / utils / TapiUtils.java
1 /*
2  * Copyright © 2018 Orange, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.transportpce.tapi.utils;
9
10 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.equipment.types.rev181130.OpticTypes;
11 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.node.types.rev181130.NodeIdType;
12 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.ConnectionType;
13 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.RpcActions;
14 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.sdnc.request.header.SdncRequestHeaderBuilder;
15 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.service.endpoint.RxDirectionBuilder;
16 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.service.endpoint.TxDirectionBuilder;
17 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.service.lgx.LgxBuilder;
18 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.service.port.PortBuilder;
19 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.format.rev190531.ServiceFormat;
20 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceCreateInput;
21 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceCreateInputBuilder;
22 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.service.create.input.ServiceAEnd;
23 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.service.create.input.ServiceAEndBuilder;
24 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.service.create.input.ServiceZEnd;
25 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.service.create.input.ServiceZEndBuilder;
26 import org.opendaylight.yangtools.yang.common.Uint32;
27
28 public final class TapiUtils {
29
30     private static final String LGX_PORT_NAME = "Some lgx-port-name";
31     private static final String PORT_TYPE = "some port type";
32     private static final String LGX_DEVICE_NAME = "Some lgx-device-name";
33     private static final String PORT_RACK_VALUE = "000000.00";
34
35     private TapiUtils() {
36     }
37
38     public static ServiceCreateInput buildServiceCreateInput(GenericServiceEndpoint sepA, GenericServiceEndpoint sepZ) {
39         ServiceCreateInputBuilder builtInput = new ServiceCreateInputBuilder();
40         ServiceAEnd serviceAEnd = getServiceAEnd(sepA, sepZ);
41         ServiceZEnd serviceZEnd = getServiceZEnd(sepA, sepZ);
42         if (serviceAEnd != null && serviceZEnd != null) {
43             builtInput.setCommonId("commonId");
44             builtInput.setConnectionType(ConnectionType.Service);
45             builtInput.setCustomer("Customer");
46             builtInput.setServiceName("service test");
47             builtInput.setServiceAEnd(serviceAEnd);
48             builtInput.setServiceZEnd(serviceZEnd);
49             builtInput.setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("request-1")
50                 .setRpcAction(RpcActions.ServiceCreate).setNotificationUrl("notification url").setRequestSystemId(
51                     "appname")
52                 .build());
53         } else {
54             return null;
55         }
56         return builtInput.build();
57     }
58
59     public static ServiceAEnd buildServiceAEnd(String nodeid, String clli, String txPortDeviceName,
60         String txPortName, String rxPortDeviceName, String rxPortName) {
61         return new ServiceAEndBuilder()
62                 .setClli(clli)
63                 .setNodeId(new NodeIdType(nodeid))
64                 .setOpticType(OpticTypes.Gray)
65                 .setServiceFormat(ServiceFormat.Ethernet)
66                 .setServiceRate(Uint32.valueOf(100))
67                 .setTxDirection(new TxDirectionBuilder()
68                         .setPort(new PortBuilder()
69                                 .setPortDeviceName(txPortDeviceName)
70                                 .setPortName(txPortName)
71                                 .setPortRack(PORT_RACK_VALUE)
72                                 .setPortShelf("00")
73                                 .setPortType(PORT_TYPE)
74                                 .build())
75                         .setLgx(new LgxBuilder()
76                                 .setLgxDeviceName(LGX_DEVICE_NAME)
77                                 .setLgxPortName(LGX_PORT_NAME)
78                                 .setLgxPortRack(PORT_RACK_VALUE)
79                                 .setLgxPortShelf("00")
80                                 .build())
81                         .build())
82                 .setRxDirection(new RxDirectionBuilder()
83                         .setPort(new PortBuilder()
84                                 .setPortDeviceName(rxPortDeviceName)
85                                 .setPortName(rxPortName)
86                         .setPortRack(PORT_RACK_VALUE)
87                         .setPortShelf("00")
88                         .setPortType(PORT_TYPE)
89                         .build())
90                         .setLgx(new LgxBuilder()
91                                 .setLgxDeviceName(LGX_DEVICE_NAME)
92                                 .setLgxPortName(LGX_PORT_NAME)
93                                 .setLgxPortRack(PORT_RACK_VALUE)
94                                 .setLgxPortShelf("00")
95                                 .build())
96                         .build())
97                 .build();
98     }
99
100     public static ServiceZEnd buildServiceZEnd(String nodeid, String clli, String txPortDeviceName,
101         String txPortName, String rxPortDeviceName, String rxPortName) {
102         return  new ServiceZEndBuilder().setClli(clli).setNodeId(new NodeIdType(nodeid))
103                 .setOpticType(OpticTypes.Gray)
104                 .setServiceFormat(ServiceFormat.Ethernet)
105                 .setServiceRate(Uint32.valueOf(100))
106                 .setTxDirection(new TxDirectionBuilder()
107                         .setPort(new PortBuilder()
108                                 .setPortDeviceName(txPortDeviceName)
109                                 .setPortName(txPortName)
110                                 .setPortRack(PORT_RACK_VALUE)
111                                 .setPortShelf("00")
112                                 .setPortType(PORT_TYPE)
113                                 .build())
114                         .setLgx(new LgxBuilder()
115                                 .setLgxDeviceName(LGX_DEVICE_NAME)
116                                 .setLgxPortName(LGX_PORT_NAME)
117                                 .setLgxPortRack(PORT_RACK_VALUE)
118                                 .setLgxPortShelf("00")
119                                 .build())
120                         .build())
121                 .setRxDirection(new RxDirectionBuilder()
122                         .setPort(new PortBuilder()
123                                 .setPortDeviceName(rxPortDeviceName)
124                                 .setPortName(rxPortName)
125                                 .setPortRack(PORT_RACK_VALUE)
126                                 .setPortShelf("00")
127                                 .setPortType(PORT_TYPE)
128                                 .build())
129                         .setLgx(new LgxBuilder()
130                                 .setLgxDeviceName(LGX_DEVICE_NAME)
131                                 .setLgxPortName(LGX_PORT_NAME)
132                                 .setLgxPortRack(PORT_RACK_VALUE)
133                                 .setLgxPortShelf("00")
134                                 .build())
135                         .build())
136                 .build();
137     }
138
139     private static ServiceAEnd getServiceAEnd(GenericServiceEndpoint sepA, GenericServiceEndpoint sepZ) {
140         if (sepA.getType().equals(ServiceEndpointType.SERVICEAEND)) {
141             return new ServiceAEndBuilder(sepA.getValue()).build();
142         } else if (sepZ.getType().equals(ServiceEndpointType.SERVICEAEND)) {
143             return new ServiceAEndBuilder(sepZ.getValue()).build();
144         } else {
145             return null;
146         }
147     }
148
149     private static ServiceZEnd getServiceZEnd(GenericServiceEndpoint sepA, GenericServiceEndpoint sepZ) {
150         if (sepA.getType().equals(ServiceEndpointType.SERVICEZEND)) {
151             return new ServiceZEndBuilder(sepA.getValue()).build();
152         } else if (sepZ.getType().equals(ServiceEndpointType.SERVICEZEND)) {
153             return new ServiceZEndBuilder(sepZ.getValue()).build();
154         } else {
155             return null;
156         }
157     }
158 }