Fixup Augmentable and Identifiable methods changing
[neutron.git] / transcriber / src / main / java / org / opendaylight / neutron / transcriber / NeutronSFCPortChainInterface.java
1 /*
2  * Copyright (c) 2016 Brocade Communications Systems, 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.neutron.transcriber;
9
10 import java.util.ArrayList;
11 import java.util.HashMap;
12 import java.util.List;
13 import javax.inject.Inject;
14 import javax.inject.Singleton;
15 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
16 import org.opendaylight.neutron.spi.INeutronSFCPortChainCRUD;
17 import org.opendaylight.neutron.spi.NeutronSFCPortChain;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.sfc.rev160511.port.chain.attributes.ChainParameters;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.sfc.rev160511.port.chain.attributes.ChainParametersBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.sfc.rev160511.port.chain.attributes.ChainParametersKey;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.sfc.rev160511.sfc.attributes.PortChains;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.sfc.rev160511.sfc.attributes.port.chains.PortChain;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.sfc.rev160511.sfc.attributes.port.chains.PortChainBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.sfc.rev160511.sfc.attributes.port.chains.PortChainKey;
26 import org.ops4j.pax.cdi.api.OsgiServiceProvider;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29
30 /**
31  * Created by Anil Vishnoi (avishnoi@Brocade.com).
32  */
33 @Singleton
34 @OsgiServiceProvider(classes = INeutronSFCPortChainCRUD.class)
35 public final class NeutronSFCPortChainInterface
36         extends AbstractNeutronInterface<PortChain, PortChains, PortChainKey, NeutronSFCPortChain>
37         implements INeutronSFCPortChainCRUD {
38
39     private static final Logger LOG = LoggerFactory.getLogger(NeutronSFCPortChainInterface.class);
40
41     @Inject
42     public NeutronSFCPortChainInterface(DataBroker db) {
43         super(PortChainBuilder.class, db);
44     }
45
46     @Override
47     protected List<PortChain> getDataObjectList(PortChains dataObjects) {
48         return dataObjects.getPortChain();
49     }
50
51     @Override
52     protected PortChain toMd(NeutronSFCPortChain neutronPortChain) {
53
54         LOG.trace("toMd: REST SFC Port Chain data : {}", neutronPortChain);
55
56         PortChainBuilder result = new PortChainBuilder();
57         toMdBaseAttributes(neutronPortChain, result);
58         if (neutronPortChain.getPortPairGroupsUUID() != null) {
59             List<Uuid> portPairGroups = new ArrayList<>();
60             for (String uuid : neutronPortChain.getPortPairGroupsUUID()) {
61                 portPairGroups.add(new Uuid(uuid));
62             }
63             result.setPortPairGroups(portPairGroups);
64         }
65         if (neutronPortChain.getFlowClassifiersUUID() != null) {
66             List<Uuid> flowClassifiers = new ArrayList<>();
67             for (String uuid : neutronPortChain.getFlowClassifiersUUID()) {
68                 flowClassifiers.add(new Uuid(uuid));
69             }
70             result.setFlowClassifiers(flowClassifiers);
71         }
72         if (neutronPortChain.getChainParameters() != null) {
73             List<ChainParameters> chainParams = new ArrayList<>();
74             for (String paramKey : neutronPortChain.getChainParameters().keySet()) {
75                 ChainParametersBuilder param = new ChainParametersBuilder();
76                 param.withKey(new ChainParametersKey(paramKey));
77                 param.setChainParameter(paramKey);
78                 param.setChainParameterValue(neutronPortChain.getChainParameters().get(paramKey));
79                 chainParams.add(param.build());
80             }
81             result.setChainParameters(chainParams);
82         }
83         LOG.trace("toMd: Yang SFC Port Chain data : {}", result);
84         return result.build();
85     }
86
87     @Override
88     protected NeutronSFCPortChain fromMd(PortChain mdPortChain) {
89         LOG.trace("fromMd: Yang SFC Port Chain data : {}", mdPortChain);
90         NeutronSFCPortChain result = new NeutronSFCPortChain();
91         fromMdBaseAttributes(mdPortChain, result);
92         if (mdPortChain.getPortPairGroups() != null) {
93             List<String> portPairGroups = new ArrayList<>();
94             for (Uuid uuid : mdPortChain.getPortPairGroups()) {
95                 portPairGroups.add(uuid.getValue());
96             }
97             result.setPortPairGroupsUUID(portPairGroups);
98         }
99         if (mdPortChain.getFlowClassifiers() != null) {
100             List<String> flowClassifiers = new ArrayList<>();
101             for (Uuid uuid : mdPortChain.getFlowClassifiers()) {
102                 flowClassifiers.add(uuid.getValue());
103             }
104             result.setFlowClassifiersUUID(flowClassifiers);
105         }
106         if (mdPortChain.getChainParameters() != null) {
107             HashMap<String, String> chainParams = new HashMap<>();
108             for (ChainParameters param : mdPortChain.getChainParameters()) {
109                 chainParams.put(param.getChainParameter(), param.getChainParameterValue());
110             }
111             result.setChainParameters(chainParams);
112         }
113         LOG.trace("fromMd: REST SFC Port Chain data : {}", result);
114         return result;
115     }
116 }