transscriber: consolidate createInstanceIdentifier(T item)
[neutron.git] / transcriber / src / main / java / org / opendaylight / neutron / transcriber / NeutronSFCPortPairInterface.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 org.opendaylight.controller.md.sal.binding.api.DataBroker;
14 import org.opendaylight.neutron.spi.INeutronSFCPortPairCRUD;
15 import org.opendaylight.neutron.spi.NeutronSFCPortPair;
16 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.sfc.rev160511.port.pair.attributes.ServiceFunctionParameters;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.sfc.rev160511.port.pair.attributes.ServiceFunctionParametersBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.sfc.rev160511.port.pair.attributes.ServiceFunctionParametersKey;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.sfc.rev160511.sfc.attributes.PortPairs;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.sfc.rev160511.sfc.attributes.port.pairs.PortPair;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.sfc.rev160511.sfc.attributes.port.pairs.PortPairBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.sfc.rev160511.sfc.attributes.port.pairs.PortPairKey;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26
27 /**
28  * Created by Anil Vishnoi (avishnoi@Brocade.com)
29  */
30 public final class NeutronSFCPortPairInterface
31         extends AbstractNeutronInterface<PortPair, PortPairs, PortPairKey, NeutronSFCPortPair>
32         implements INeutronSFCPortPairCRUD {
33
34     private static final Logger LOGGER = LoggerFactory.getLogger(NeutronSFCPortPairInterface.class);
35
36     NeutronSFCPortPairInterface(DataBroker db) {
37         super(PortPairBuilder.class, db);
38     }
39
40     @Override
41     protected PortPair toMd(NeutronSFCPortPair neutronPortPair) {
42
43         LOGGER.trace("toMd: REST SFC Port Pair data : {}", neutronPortPair);
44
45         PortPairBuilder result = new PortPairBuilder();
46         toMdBaseAttributes(neutronPortPair, result);
47         if (neutronPortPair.getIngressPortUUID() != null) {
48             result.setIngress(new Uuid(neutronPortPair.getIngressPortUUID()));
49         }
50         if (neutronPortPair.getEgressPortUUID() != null) {
51             result.setEgress(new Uuid(neutronPortPair.getEgressPortUUID()));
52         }
53         if (neutronPortPair.getServiceFunctionParameters() != null) {
54             List<ServiceFunctionParameters> serviceFunctionParams = new ArrayList<>();
55             for (String paramKey : neutronPortPair.getServiceFunctionParameters().keySet()) {
56                 ServiceFunctionParametersBuilder param = new ServiceFunctionParametersBuilder();
57                 param.setKey(new ServiceFunctionParametersKey(paramKey));
58                 param.setServiceFunctionParameter(paramKey);
59                 param.setServiceFunctionParameterValue(neutronPortPair.getServiceFunctionParameters().get(paramKey));
60                 serviceFunctionParams.add(param.build());
61             }
62             result.setServiceFunctionParameters(serviceFunctionParams);
63         }
64         LOGGER.trace("toMd: Yang SFC Port Pair data : {}", result);
65         return result.build();
66     }
67
68     @Override
69     protected NeutronSFCPortPair fromMd(PortPair mdPortPair) {
70         LOGGER.trace("fromMd: Yang SFC Port Pair data : {}", mdPortPair);
71         NeutronSFCPortPair result = new NeutronSFCPortPair();
72         fromMdBaseAttributes(mdPortPair, result);
73         if (mdPortPair.getIngress() != null) {
74             result.setIngressPortUUID(mdPortPair.getIngress().getValue());
75         }
76         if (mdPortPair.getEgress() != null) {
77             result.setEgressPortUUID(mdPortPair.getEgress().getValue());
78         }
79         if (mdPortPair.getServiceFunctionParameters() != null) {
80             HashMap<String, String> serviceFunctionParam = new HashMap<>();
81             for (ServiceFunctionParameters param : mdPortPair.getServiceFunctionParameters()) {
82                 serviceFunctionParam.put(param.getServiceFunctionParameter(), param.getServiceFunctionParameterValue());
83             }
84             result.setServiceFunctionParameters(serviceFunctionParam);
85         }
86         LOGGER.trace("fromMd: REST SFC Port Pair data : {}", result);
87         return result;
88     }
89
90     @Override
91     protected List<PortPair> getDataObjectList(PortPairs dataObjects) {
92         return dataObjects.getPortPair();
93     }
94
95 }