Code Clean up: remove type from <>
[neutron.git] / transcriber / src / main / java / org / opendaylight / neutron / transcriber / NeutronL2gatewayInterface.java
1 /*
2  * Copyright (c) 2015 Hewlett-Packard Development Company, L.P. 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
9 package org.opendaylight.neutron.transcriber;
10
11 import java.util.ArrayList;
12 import java.util.List;
13 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
14 import org.opendaylight.neutron.spi.INeutronL2gatewayCRUD;
15 import org.opendaylight.neutron.spi.NeutronL2gateway;
16 import org.opendaylight.neutron.spi.NeutronL2gatewayDevice;
17 import org.opendaylight.neutron.spi.NeutronL2gatewayDeviceInterface;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.attributes.Devices;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.attributes.DevicesBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.attributes.devices.Interfaces;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.attributes.devices.InterfacesBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateways.attributes.L2gateways;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateways.attributes.l2gateways.L2gateway;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateways.attributes.l2gateways.L2gatewayBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateways.attributes.l2gateways.L2gatewayKey;
26
27 public final class NeutronL2gatewayInterface
28         extends AbstractNeutronInterface<L2gateway, L2gateways, L2gatewayKey, NeutronL2gateway>
29         implements INeutronL2gatewayCRUD {
30     NeutronL2gatewayInterface(DataBroker db) {
31         super(L2gatewayBuilder.class, db);
32     }
33
34     @Override
35     protected List<L2gateway> getDataObjectList(L2gateways l2gateways) {
36         return l2gateways.getL2gateway();
37     }
38
39     @Override
40     protected NeutronL2gateway fromMd(L2gateway l2gateway) {
41         final NeutronL2gateway result = new NeutronL2gateway();
42         final List<NeutronL2gatewayDevice> neutronL2gatewayDevices = new ArrayList<>();
43
44         if (l2gateway.getUuid() != null) {
45             result.setID(l2gateway.getUuid().getValue());
46         }
47         if (l2gateway.getL2gatewayName() != null) {
48             result.setName(String.valueOf(l2gateway.getL2gatewayName()));
49         }
50         if (l2gateway.getTenantId() != null) {
51             result.setTenantID(l2gateway.getTenantId());
52         }
53         if (l2gateway.getDevices() != null) {
54             for (final Devices device : l2gateway.getDevices()) {
55                 final NeutronL2gatewayDevice neutronL2gatewayDevice = new NeutronL2gatewayDevice();
56                 final List<NeutronL2gatewayDeviceInterface> neutronL2gatewayDeviceInterfaces = new ArrayList<>();
57                 if (device.getDeviceName() != null) {
58                     neutronL2gatewayDevice.setDeviceName(device.getDeviceName().toString());
59                 }
60                 if (device.getUuid() != null) {
61                     neutronL2gatewayDevice.setID(device.getUuid().getValue());
62                 }
63                 if (device.getInterfaces() != null) {
64                     for (final Interfaces deviceInterface : device.getInterfaces()) {
65                         final NeutronL2gatewayDeviceInterface neutronL2gatewayDeviceInterface =
66                                 new NeutronL2gatewayDeviceInterface();
67                         String interfaceName = null;
68                         final List<Integer> segmentationIds = new ArrayList<>();
69                         if (deviceInterface.getInterfaceName() != null) {
70                             interfaceName = deviceInterface.getInterfaceName().toString();
71                         }
72                         if (deviceInterface.getSegmentationIds() != null) {
73                             for (final Integer segmentId : deviceInterface.getSegmentationIds()) {
74                                 segmentationIds.add(segmentId);
75                             }
76                             neutronL2gatewayDeviceInterface.setSegmentationId(segmentationIds);
77                         }
78                         neutronL2gatewayDeviceInterface.setInterfaceName(interfaceName);
79                         neutronL2gatewayDeviceInterfaces.add(neutronL2gatewayDeviceInterface);
80                     }
81                 }
82                 neutronL2gatewayDevice.setNeutronL2gatewayDeviceInterfaces(neutronL2gatewayDeviceInterfaces);
83                 neutronL2gatewayDevices.add(neutronL2gatewayDevice);
84             }
85         }
86         result.setNeutronL2gatewayDevices(neutronL2gatewayDevices);
87         return result;
88     }
89
90     @Override
91     protected L2gateway toMd(NeutronL2gateway neutronObject) {
92         final L2gatewayBuilder l2gatewayBuilder = new L2gatewayBuilder();
93         if (neutronObject.getName() != null) {
94             l2gatewayBuilder.setL2gatewayName(neutronObject.getName());
95         }
96         if (neutronObject.getID() != null) {
97             l2gatewayBuilder.setUuid(toUuid(neutronObject.getID()));
98         }
99         if (neutronObject.getTenantID() != null) {
100             l2gatewayBuilder.setTenantId(toUuid(neutronObject.getTenantID()));
101         }
102
103         if (neutronObject.getNeutronL2gatewayDevices() != null) {
104             final List<Devices> devices = new ArrayList<>();
105             for (final NeutronL2gatewayDevice neutronL2gatewayDevice : neutronObject.getNeutronL2gatewayDevices()) {
106                 final DevicesBuilder deviceBuilder = new DevicesBuilder();
107                 final List<Interfaces> interfaces = new ArrayList<Interfaces>();
108                 for (final NeutronL2gatewayDeviceInterface neutronL2gatewayDeviceInterface : neutronL2gatewayDevice
109                         .getNeutronL2gatewayDeviceInterfaces()) {
110                     final InterfacesBuilder interfacesBuilder = new InterfacesBuilder();
111                     final List<Integer> segmentIds = new ArrayList<>();
112                     interfacesBuilder.setInterfaceName(neutronL2gatewayDeviceInterface.getInterfaceName());
113                     if (neutronL2gatewayDeviceInterface.getSegmentationId() != null) {
114                         for (final Integer segmentationId : neutronL2gatewayDeviceInterface.getSegmentationId()) {
115                             segmentIds.add(segmentationId);
116                         }
117                         interfacesBuilder.setSegmentationIds(segmentIds);
118                     }
119                     interfaces.add(interfacesBuilder.build());
120                 }
121                 deviceBuilder.setDeviceName(neutronL2gatewayDevice.getDeviceName());
122                 deviceBuilder.setUuid(toUuid(neutronL2gatewayDevice.getID()));
123                 deviceBuilder.setInterfaces(interfaces);
124                 devices.add(deviceBuilder.build());
125             }
126             l2gatewayBuilder.setDevices(devices);
127         }
128         return l2gatewayBuilder.build();
129     }
130 }