remove dead code pointed out by sonar
[transportpce.git] / servicehandler / src / main / java / org / opendaylight / transportpce / servicehandler / MappingConstraints.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
10 package org.opendaylight.transportpce.servicehandler;
11
12 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.Constraints;
13 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.CoRoutingOrGeneral;
14 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.co.routing.or.general.CoRouting;
15 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.co.routing.or.general.General;
16 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.co.routing.or.general.general.Diversity;
17 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.co.routing.or.general.general.Exclude;
18 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.co.routing.or.general.general.Include;
19 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.co.routing.or.general.general.Latency;
20 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.routing.constraints.HardConstraints;
21 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.routing.constraints.SoftConstraints;
22 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.ConstraintsSp;
23 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.constraints.sp.co.routing.or.general.co.routing.CoRoutingBuilder;
24 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.constraints.sp.co.routing.or.general.general.DiversityBuilder;
25 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.constraints.sp.co.routing.or.general.general.ExcludeBuilder;
26 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.constraints.sp.co.routing.or.general.general.IncludeBuilder;
27 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.constraints.sp.co.routing.or.general.general.LatencyBuilder;
28 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.diversity.existing.service.contraints.sp.ExistingServiceApplicabilityBuilder;
29 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.routing.constraints.sp.HardConstraintsBuilder;
30 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.routing.constraints.sp.SoftConstraintsBuilder;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33
34 /**
35  * Class for mapping
36  * Hard/soft constraint from Service 1.2
37  * to servicePath 1.4.
38  * @author Martial Coulibaly ( martial.coulibaly@gfi.com ) on behalf of Orange
39  *
40  */
41 public class MappingConstraints {
42     /** Logging. */
43     private static final Logger LOG = LoggerFactory.getLogger(MappingConstraints.class);
44     private HardConstraints serviceHardConstraints;
45     private SoftConstraints serviceSoftConstraints;
46     private org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
47         .routing.constraints.rev171017.routing.constraints.sp.HardConstraints servicePathHardConstraints;
48     private org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
49         .routing.constraints.rev171017.routing.constraints.sp.SoftConstraints servicePathSoftConstraints;
50
51     /**
52      * MappingConstraints class constructor
53      * for hard/soft from service 1.2.
54      *
55      * @param hard HardConstraints
56      * @param soft SoftConstraints
57      */
58     public MappingConstraints(HardConstraints hard, SoftConstraints soft) {
59         setServiceHardConstraints(hard);
60         setServiceSoftConstraints(soft);
61     }
62
63     /**
64      * MappingConstraints class constructor
65      * for hard/soft from servicePath 1.4.
66      *
67      * @param hard HardConstraints
68      * @param soft SoftConstraints
69      */
70     public MappingConstraints(org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
71             .routing.constraints.rev171017.routing.constraints.sp.HardConstraints hard,
72             org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
73             .routing.constraints.rev171017.routing.constraints.sp.SoftConstraints soft) {
74         setServicePathHardConstraints(hard);
75         setServicePathSoftConstraints(soft);
76     }
77
78     /**
79      *get all constraints informations
80      *from service constraints to map to
81      *servicePath constraints.
82      *
83      * @param input HardConstraints or SoftConstraints
84      * @return ConstraintsSp HardConstraintsSp or HardConstraintsSp
85      */
86     private <T> ConstraintsSp getConstraints(T input) {
87         CoRoutingOrGeneral coRoutingOrGeneral = null;
88         HardConstraintsBuilder tempHard = new HardConstraintsBuilder();
89         SoftConstraintsBuilder tempSoft = new SoftConstraintsBuilder();
90         if ((input  !=  null) && (input instanceof Constraints)) {
91             Constraints constraints = (Constraints)input;
92             coRoutingOrGeneral = constraints.getCoRoutingOrGeneral();
93             General tmpGeneral = null;
94             CoRouting tmpCoRouting = null;
95             if (coRoutingOrGeneral  !=  null) {
96                 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints
97                     .rev171017.constraints.sp.co.routing.or.general.GeneralBuilder finalGeneral =
98                     new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints
99                     .rev171017.constraints.sp.co.routing.or.general.GeneralBuilder();
100                 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints
101                     .rev171017.constraints.sp.co.routing.or.general.CoRoutingBuilder finalCoRouting =
102                     new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints
103                     .rev171017.constraints.sp.co.routing.or.general.CoRoutingBuilder();
104                 if (coRoutingOrGeneral instanceof General) {
105                     tmpGeneral = (General) coRoutingOrGeneral;
106                     if (tmpGeneral  !=  null) {
107                         Diversity tmpDiversity =  tmpGeneral.getDiversity();
108                         if (tmpDiversity  !=  null) {
109                             finalGeneral.setDiversity(
110                                     new DiversityBuilder()
111                                     .setExistingService(tmpDiversity.getExistingService())
112                                     .setExistingServiceApplicability(
113                                             new ExistingServiceApplicabilityBuilder()
114                                             .setClli(tmpDiversity.getExistingServiceApplicability().isSite())
115                                             .setNode(tmpDiversity.getExistingServiceApplicability().isNode())
116                                             .setSrlg(tmpDiversity.getExistingServiceApplicability().isSrlg())
117                                             .build())
118                                     .build());
119                         }
120                         Exclude tmpExclude = tmpGeneral.getExclude();
121                         if (tmpExclude  !=  null) {
122                             finalGeneral.setExclude(
123                                     new ExcludeBuilder()
124                                     .setSupportingServiceName(tmpExclude.getSupportingServiceName())
125                                     .setClli(tmpExclude.getSite())
126                                     .setNodeId(tmpExclude.getNodeId())
127                                     //.setAffinity(value)
128                                     //.setSRLG(value)
129                                     .build());
130                         }
131                         Include tmpInclude = tmpGeneral.getInclude();
132                         if (tmpInclude  !=  null) {
133                             finalGeneral.setInclude(
134                                     new IncludeBuilder()
135                                     //.setOrderedHops()
136                                     .build());
137                         }
138                         Latency tmpLatency = tmpGeneral.getLatency();
139                         if (tmpLatency != null) {
140                             finalGeneral.setLatency(
141                                     new LatencyBuilder()
142                                     .setMaxLatency(tmpLatency.getMaxLatency())
143                                     .build());
144                         }
145                     }
146                     tempHard.setCoRoutingOrGeneral(finalGeneral.build())
147                         .setCustomerCode(constraints.getCustomerCode());
148                     tempSoft.setCoRoutingOrGeneral(finalGeneral.build())
149                         .setCustomerCode(constraints.getCustomerCode());
150                 } else if (coRoutingOrGeneral instanceof CoRouting) {
151                     tmpCoRouting = (CoRouting)coRoutingOrGeneral;
152                     if (tmpCoRouting  !=  null) {
153                         org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014
154                             .constraints.co.routing.or.general.co.routing.CoRouting tmpCoRoutingCoRouting =
155                             tmpCoRouting.getCoRouting();
156                         if (tmpCoRoutingCoRouting  !=  null) {
157                             finalCoRouting.setCoRouting(
158                                     new CoRoutingBuilder()
159                                     .setExistingService(tmpCoRoutingCoRouting.getExistingService())
160                                     .build());
161                         }
162                     }
163                     tempHard.setCoRoutingOrGeneral(finalCoRouting.build())
164                         .setCustomerCode(constraints.getCustomerCode());
165                     tempSoft.setCoRoutingOrGeneral(finalCoRouting.build())
166                         .setCustomerCode(constraints.getCustomerCode());
167                 }
168             }
169         }
170         if (input instanceof HardConstraints) {
171             return tempHard.build();
172         } else if (input instanceof SoftConstraints) {
173             return tempSoft.build();
174         } else {
175             return null;
176         }
177     }
178
179     /**
180      * map hard/soft constraints from Service 1.2
181      * to ServicePath 1.4.
182      */
183     public void serviceToServicePathConstarints() {
184         LOG.info("Mapping Service Constraints to ServicePath Constraints");
185         if (serviceHardConstraints  !=  null) {
186             org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints
187                 .rev171017.routing.constraints.sp.HardConstraints tempHard = (org.opendaylight.yang.gen
188                     .v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.routing
189                     .constraints.sp.HardConstraints) getConstraints(serviceHardConstraints);
190             if (tempHard != null) {
191                 servicePathHardConstraints = tempHard;
192             }
193         } else if (serviceSoftConstraints  !=  null) {
194             org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints
195                 .rev171017.routing.constraints.sp.SoftConstraints tempSoft = (org.opendaylight.yang.gen
196                     .v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.routing
197                     .constraints.sp.SoftConstraints) getConstraints(serviceSoftConstraints);
198             if (tempSoft != null) {
199                 servicePathSoftConstraints = tempSoft;
200             }
201         }
202     }
203
204
205     public HardConstraints getServiceHardConstraints() {
206         return serviceHardConstraints;
207     }
208
209
210     public void setServiceHardConstraints(HardConstraints serviceHardConstraints) {
211         this.serviceHardConstraints = serviceHardConstraints;
212     }
213
214
215     public SoftConstraints getServiceSoftConstraints() {
216         return serviceSoftConstraints;
217     }
218
219
220     public void setServiceSoftConstraints(SoftConstraints serviceSoftConstraints) {
221         this.serviceSoftConstraints = serviceSoftConstraints;
222     }
223
224
225     public org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
226         .routing.constraints.rev171017.routing.constraints.sp.HardConstraints getServicePathHardConstraints() {
227         return servicePathHardConstraints;
228     }
229
230
231     public void setServicePathHardConstraints(org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
232             .routing.constraints.rev171017.routing.constraints.sp.HardConstraints servicePathHardConstraints) {
233         this.servicePathHardConstraints = servicePathHardConstraints;
234     }
235
236
237     public org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
238         .routing.constraints.rev171017.routing.constraints.sp.SoftConstraints getServicePathSoftConstraints() {
239         return servicePathSoftConstraints;
240     }
241
242
243     public void setServicePathSoftConstraints(org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
244             .routing.constraints.rev171017.routing.constraints.sp.SoftConstraints servicePathSoftConstraints) {
245         this.servicePathSoftConstraints = servicePathSoftConstraints;
246     }
247
248 }