bump dependencies to Mg SR2 dev versions
[transportpce.git] / tapi / src / main / java / org / opendaylight / transportpce / tapi / utils / MappingUtils.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 java.util.HashMap;
11 import java.util.Map;
12 import java.util.Map.Entry;
13 import java.util.Set;
14 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.service.create.input.ServiceAEnd;
15 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.service.create.input.ServiceZEnd;
16 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.Uuid;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.tapi.rev180928.EndPointType;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.tapi.rev180928.service._interface.points.ServiceEndPoint;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
21
22 public final class MappingUtils {
23
24     private static final Logger LOG = LoggerFactory.getLogger(MappingUtils.class);
25
26     private static Map<Uuid, GenericServiceEndpoint> map = new HashMap<Uuid, GenericServiceEndpoint>();
27
28     private MappingUtils() {
29     }
30
31     private static GenericServiceEndpoint createMapEntry(ServiceEndPoint sep) {
32         if (sep.getEndPoint().getServiceEndPointType().equals(EndPointType.Aend)) {
33             ServiceAEnd sepG = TapiUtils.buildServiceAEnd(sep.getEndPoint().getNodeId().getValue(), sep.getEndPoint()
34                 .getClli(), sep.getEndPoint().getTxDirection().getPort().getPortDeviceName(), sep.getEndPoint()
35                     .getTxDirection().getPort().getPortName(),
36                 sep.getEndPoint().getRxDirection().getPort().getPortDeviceName(), sep.getEndPoint().getRxDirection()
37                     .getPort().getPortName());
38             return new GenericServiceEndpoint(sepG, ServiceEndpointType.SERVICEAEND);
39         } else {
40             ServiceZEnd sepG = TapiUtils.buildServiceZEnd(sep.getEndPoint().getNodeId().getValue(), sep.getEndPoint()
41                 .getClli(), sep.getEndPoint().getTxDirection().getPort().getPortDeviceName(), sep.getEndPoint()
42                     .getTxDirection().getPort().getPortName(),
43                 sep.getEndPoint().getRxDirection().getPort().getPortDeviceName(), sep.getEndPoint().getRxDirection()
44                     .getPort().getPortName());
45             return new GenericServiceEndpoint(sepG, ServiceEndpointType.SERVICEZEND);
46         }
47     }
48
49     public static void addMapSEP(ServiceEndPoint sep) {
50         Uuid uuid = sep.getUuid();
51         if (!map.containsKey(uuid)) {
52             LOG.info("adding new entry {} into static map", uuid);
53             map.put(uuid, MappingUtils.createMapEntry(sep));
54         } else {
55             LOG.error("service-end-point entry already exist. Please DELETE it before PUT it...");
56         }
57     }
58
59     public static void deleteMapEntry(Uuid uuid) {
60         if (map.containsKey(uuid)) {
61             LOG.info("map size = {}", Integer.toString(map.size()));
62             map.remove(uuid);
63             LOG.info("map size = {}", Integer.toString(map.size()));
64         } else {
65             LOG.info("No existing entry with uuid {}", uuid);
66         }
67     }
68
69     public static void afficheMap() {
70         if (!map.isEmpty()) {
71             Set<Entry<Uuid, GenericServiceEndpoint>> entries = map.entrySet();
72             LOG.info("Displaying the static map...");
73             for (Entry<Uuid, GenericServiceEndpoint> entry : entries) {
74                 LOG.info("uuid = {} \t service end point = {}", entry.getKey().toString(), entry.getValue().getValue()
75                     .toString());
76             }
77         } else {
78             LOG.info("Static map is empty - Nothing to display");
79         }
80
81     }
82
83     public static void deleteMap() {
84         if (!map.isEmpty()) {
85             map.clear();
86         } else {
87             LOG.info("Static map is already empty - Nothing to delete");
88         }
89     }
90
91     public static Map<Uuid, GenericServiceEndpoint> getMap() {
92         return map;
93     }
94
95 }