Stubpce Update
[transportpce.git] / tests / stubpce / src / main / java / org / opendaylight / transportpce / stubpce / topology / SuperNode.java
1 /*
2  * Copyright © 2017 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
9 package org.opendaylight.transportpce.stubpce.topology;
10
11 import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
12 import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
13 import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
14
15 import java.util.ArrayList;
16 import java.util.List;
17
18
19 /**
20  * class to create Supernode
21  * structure.
22  *
23  * @author <a href="mailto:martial.coulibaly@gfi.com">Martial Coulibaly</a> on
24  *         behalf of Orange
25  */
26 @JacksonXmlRootElement(localName = "super-node")
27 public class SuperNode {
28     /** Supernode Id. */
29     @JacksonXmlProperty(localName = "super-node-id")
30     private String superNodeId;
31     /** list of elements cotaining in Supernode. */
32     @JacksonXmlElementWrapper(localName = "resources")
33     @JacksonXmlProperty(localName = "resource")
34     private List<Resource> resources;
35
36     /**
37      * SuperNode constructor.
38      *
39      * @param supernodeid superNode Id
40      * @param resources List of Supernode elements
41      */
42     public SuperNode(@JacksonXmlProperty(localName = "super-node-id") final String supernodeid,
43             @JacksonXmlProperty(localName = "Spresource") final List<Resource> resources) {
44         setSuperNodeId(supernodeid);
45         setResources(resources);
46     }
47
48     /**
49      * SuperNode constructor.
50      *
51      * @param supernodeid supernode Id
52      */
53     public SuperNode(String supernodeid) {
54         setSuperNodeId(supernodeid);
55         setResources(new ArrayList<Resource>());
56     }
57
58     /**
59      *Test if Supernode contains
60      *an XPDR.
61      * @return true if XPDR present, false else
62      */
63     public boolean isXpdrSrgAbsent() {
64         boolean result = true;
65         int present = 0;
66         if (resources.size() > 0) {
67             for (Resource resource : resources) {
68                 String nodeId = resource.getNodeId();
69                 if (nodeId != null) {
70                     if (nodeId.contains("XPDR")) {
71                         present++;
72                     }
73                     if (nodeId.contains("SRG")) {
74                         present++;
75                     }
76                 }
77             }
78         }
79         if (present == 2) {
80             result = false;
81         }
82         return result;
83     }
84
85     public List<Resource> getResources() {
86         return resources;
87     }
88
89     public void setResources(List<Resource> resources) {
90         this.resources = resources;
91     }
92
93     public String getSuperNodeId() {
94         return superNodeId;
95     }
96
97     public void setSuperNodeId(String superNodeId) {
98         this.superNodeId = superNodeId;
99     }
100
101     @Override
102     public String toString() {
103         int index;
104         int size;
105         java.lang.String name = "SuperNode [";
106         java.lang.StringBuilder builder = new java.lang.StringBuilder(name);
107         if (superNodeId != null) {
108             builder.append("superNodeId=");
109             builder.append(superNodeId);
110         }
111         index = 0;
112         size = resources.size();
113         builder.append(", Resources [");
114         for (Resource tmp : resources) {
115             builder.append(tmp.toString());
116             index++;
117             if (index < size) {
118                 builder.append(", ");
119             }
120         }
121         builder.append("]");
122         return builder.append(']').toString();
123     }
124
125 }