fix two issues in ServiceHandlerImpl
[transportpce.git] / servicehandler / src / main / java / org / opendaylight / transportpce / servicehandler / MappingConstraints.java
index cf3a09aa9dbb858c2a6283aada79accf54fb7484..f05e58dd6b77fdcaac7f9bcb72450ec762f14e7f 100644 (file)
@@ -9,6 +9,7 @@
 
 package org.opendaylight.transportpce.servicehandler;
 
+import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.Constraints;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.CoRoutingOrGeneral;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.co.routing.or.general.CoRouting;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.co.routing.or.general.General;
@@ -18,14 +19,15 @@ import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161
 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.co.routing.or.general.general.Latency;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.routing.constraints.HardConstraints;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.routing.constraints.SoftConstraints;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev170426.constraints.sp.co.routing.or.general.co.routing.CoRoutingBuilder;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev170426.constraints.sp.co.routing.or.general.general.DiversityBuilder;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev170426.constraints.sp.co.routing.or.general.general.ExcludeBuilder;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev170426.constraints.sp.co.routing.or.general.general.IncludeBuilder;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev170426.constraints.sp.co.routing.or.general.general.LatencyBuilder;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev170426.diversity.existing.service.contraints.sp.ExistingServiceApplicabilityBuilder;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev170426.routing.constraints.sp.HardConstraintsBuilder;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev170426.routing.constraints.sp.SoftConstraintsBuilder;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.ConstraintsSp;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.constraints.sp.co.routing.or.general.co.routing.CoRoutingBuilder;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.constraints.sp.co.routing.or.general.general.DiversityBuilder;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.constraints.sp.co.routing.or.general.general.ExcludeBuilder;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.constraints.sp.co.routing.or.general.general.IncludeBuilder;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.constraints.sp.co.routing.or.general.general.LatencyBuilder;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.diversity.existing.service.contraints.sp.ExistingServiceApplicabilityBuilder;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.routing.constraints.sp.HardConstraintsBuilder;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.routing.constraints.sp.SoftConstraintsBuilder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -37,14 +39,14 @@ import org.slf4j.LoggerFactory;
  *
  */
 public class MappingConstraints {
-    /* Logging. */
+    /** Logging. */
     private static final Logger LOG = LoggerFactory.getLogger(MappingConstraints.class);
     private HardConstraints serviceHardConstraints;
     private SoftConstraints serviceSoftConstraints;
     private org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
-        .routing.constraints.rev170426.routing.constraints.sp.HardConstraints servicePathHardConstraints;
+        .routing.constraints.rev171017.routing.constraints.sp.HardConstraints servicePathHardConstraints;
     private org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
-        .routing.constraints.rev170426.routing.constraints.sp.SoftConstraints servicePathSoftConstraints;
+        .routing.constraints.rev171017.routing.constraints.sp.SoftConstraints servicePathSoftConstraints;
 
     /**
      * MappingConstraints class constructor
@@ -66,34 +68,39 @@ public class MappingConstraints {
      * @param soft SoftConstraints
      */
     public MappingConstraints(org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
-            .routing.constraints.rev170426.routing.constraints.sp.HardConstraints hard,
+            .routing.constraints.rev171017.routing.constraints.sp.HardConstraints hard,
             org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
-            .routing.constraints.rev170426.routing.constraints.sp.SoftConstraints soft) {
+            .routing.constraints.rev171017.routing.constraints.sp.SoftConstraints soft) {
         setServicePathHardConstraints(hard);
         setServicePathSoftConstraints(soft);
     }
 
     /**
-     * map hard/soft constraints from Service 1.2
-     * to ServicePath 1.4.
+     *get all constraints informations
+     *from service constraints to map to
+     *servicePath constraints.
+     *
+     * @param input HardConstraints or SoftConstraints
+     * @return ConstraintsSp HardConstraintsSp or HardConstraintsSp
      */
-    public void serviceToServicePathConstarints() {
-        LOG.info("Mapping Service Constraints to ServicePath Constraints");
+    private <T> ConstraintsSp getConstraints(T input) {
         CoRoutingOrGeneral coRoutingOrGeneral = null;
-        if (serviceHardConstraints  !=  null) {
-            HardConstraintsBuilder tempHard = new HardConstraintsBuilder();
-            coRoutingOrGeneral = serviceHardConstraints.getCoRoutingOrGeneral();
+        HardConstraintsBuilder tempHard = new HardConstraintsBuilder();
+        SoftConstraintsBuilder tempSoft = new SoftConstraintsBuilder();
+        if ((input  !=  null) && (input instanceof Constraints)) {
+            Constraints constraints = (Constraints)input;
+            coRoutingOrGeneral = constraints.getCoRoutingOrGeneral();
             General tmpGeneral = null;
             CoRouting tmpCoRouting = null;
             if (coRoutingOrGeneral  !=  null) {
                 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints
-                    .rev170426.constraints.sp.co.routing.or.general.GeneralBuilder finalGeneral =
+                    .rev171017.constraints.sp.co.routing.or.general.GeneralBuilder finalGeneral =
                     new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints
-                    .rev170426.constraints.sp.co.routing.or.general.GeneralBuilder();
+                    .rev171017.constraints.sp.co.routing.or.general.GeneralBuilder();
                 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints
-                    .rev170426.constraints.sp.co.routing.or.general.CoRoutingBuilder finalCoRouting =
+                    .rev171017.constraints.sp.co.routing.or.general.CoRoutingBuilder finalCoRouting =
                     new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints
-                    .rev170426.constraints.sp.co.routing.or.general.CoRoutingBuilder();
+                    .rev171017.constraints.sp.co.routing.or.general.CoRoutingBuilder();
                 if (coRoutingOrGeneral instanceof General) {
                     tmpGeneral = (General) coRoutingOrGeneral;
                     if (tmpGeneral  !=  null) {
@@ -101,44 +108,45 @@ public class MappingConstraints {
                         if (tmpDiversity  !=  null) {
                             finalGeneral.setDiversity(
                                     new DiversityBuilder()
-                                        .setExistingService(tmpDiversity.getExistingService())
-                                        .setExistingServiceApplicability(
-                                                new ExistingServiceApplicabilityBuilder()
-                                                .setClli(tmpDiversity.getExistingServiceApplicability().isSite())
-                                                .setNode(tmpDiversity.getExistingServiceApplicability().isNode())
-                                                .setSrlg(tmpDiversity.getExistingServiceApplicability().isSrlg())
-                                                .build())
-                                        .build());
+                                    .setExistingService(tmpDiversity.getExistingService())
+                                    .setExistingServiceApplicability(
+                                            new ExistingServiceApplicabilityBuilder()
+                                            .setClli(tmpDiversity.getExistingServiceApplicability().isSite())
+                                            .setNode(tmpDiversity.getExistingServiceApplicability().isNode())
+                                            .setSrlg(tmpDiversity.getExistingServiceApplicability().isSrlg())
+                                            .build())
+                                    .build());
                         }
                         Exclude tmpExclude = tmpGeneral.getExclude();
                         if (tmpExclude  !=  null) {
                             finalGeneral.setExclude(
                                     new ExcludeBuilder()
-                                        .setSupportingServiceName(tmpExclude.getSupportingServiceName())
-                                        .setClli(tmpExclude.getSite())
-                                        .setNodeId(tmpExclude.getNodeId())
-                                        //.setAffinity(value)
-                                        //.setSRLG(value)
-                                        .build());
+                                    .setSupportingServiceName(tmpExclude.getSupportingServiceName())
+                                    .setClli(tmpExclude.getSite())
+                                    .setNodeId(tmpExclude.getNodeId())
+                                    //.setAffinity(value)
+                                    //.setSRLG(value)
+                                    .build());
                         }
                         Include tmpInclude = tmpGeneral.getInclude();
                         if (tmpInclude  !=  null) {
                             finalGeneral.setInclude(
                                     new IncludeBuilder()
-                                        //.setOrderedHops()
-                                        .build());
+                                    //.setOrderedHops()
+                                    .build());
                         }
                         Latency tmpLatency = tmpGeneral.getLatency();
                         if (tmpLatency != null) {
                             finalGeneral.setLatency(
                                     new LatencyBuilder()
-                                        .setMaxLatency(tmpLatency.getMaxLatency())
-                                        .build());
+                                    .setMaxLatency(tmpLatency.getMaxLatency())
+                                    .build());
                         }
                     }
-                    tempHard
-                        .setCoRoutingOrGeneral(finalGeneral.build())
-                        .setCustomerCode(serviceHardConstraints.getCustomerCode());
+                    tempHard.setCoRoutingOrGeneral(finalGeneral.build())
+                        .setCustomerCode(constraints.getCustomerCode());
+                    tempSoft.setCoRoutingOrGeneral(finalGeneral.build())
+                        .setCustomerCode(constraints.getCustomerCode());
                 } else if (coRoutingOrGeneral instanceof CoRouting) {
                     tmpCoRouting = (CoRouting)coRoutingOrGeneral;
                     if (tmpCoRouting  !=  null) {
@@ -148,96 +156,48 @@ public class MappingConstraints {
                         if (tmpCoRoutingCoRouting  !=  null) {
                             finalCoRouting.setCoRouting(
                                     new CoRoutingBuilder()
-                                        .setExistingService(tmpCoRoutingCoRouting.getExistingService())
-                                        .build());
+                                    .setExistingService(tmpCoRoutingCoRouting.getExistingService())
+                                    .build());
                         }
                     }
-                    tempHard
-                        .setCoRoutingOrGeneral(finalCoRouting.build())
-                        .setCustomerCode(serviceHardConstraints.getCustomerCode());
-
+                    tempHard.setCoRoutingOrGeneral(finalCoRouting.build())
+                        .setCustomerCode(constraints.getCustomerCode());
+                    tempSoft.setCoRoutingOrGeneral(finalCoRouting.build())
+                        .setCustomerCode(constraints.getCustomerCode());
                 }
             }
-            servicePathHardConstraints = tempHard.build();
-        } else if (serviceSoftConstraints  !=  null) {
-            SoftConstraintsBuilder tempSoft = new SoftConstraintsBuilder();
-            coRoutingOrGeneral = serviceSoftConstraints.getCoRoutingOrGeneral();
-            General tmpGeneral = null;
-            CoRouting tmpCoRouting = null;
-            if (coRoutingOrGeneral  !=  null) {
-                org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints
-                    .rev170426.constraints.sp.co.routing.or.general.GeneralBuilder finalGeneral =
-                    new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints
-                    .rev170426.constraints.sp.co.routing.or.general.GeneralBuilder();
-                org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints
-                    .rev170426.constraints.sp.co.routing.or.general.CoRoutingBuilder finalCoRouting =
-                    new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints
-                    .rev170426.constraints.sp.co.routing.or.general.CoRoutingBuilder();
-                if (coRoutingOrGeneral instanceof General) {
-                    tmpGeneral = (General) coRoutingOrGeneral;
-                    if (tmpGeneral  !=  null) {
-                        Diversity tmpDiversity =  tmpGeneral.getDiversity();
-                        if (tmpDiversity  !=  null) {
-                            finalGeneral.setDiversity(
-                                    new DiversityBuilder()
-                                        .setExistingService(tmpDiversity.getExistingService())
-                                        .setExistingServiceApplicability(
-                                                new ExistingServiceApplicabilityBuilder()
-                                                .setClli(tmpDiversity.getExistingServiceApplicability().isSite())
-                                                .setNode(tmpDiversity.getExistingServiceApplicability().isNode())
-                                                .setSrlg(tmpDiversity.getExistingServiceApplicability().isSrlg())
-                                                .build())
-                                        .build());
-                        }
-                        Exclude tmpExclude = tmpGeneral.getExclude();
-                        if (tmpExclude  !=  null) {
-                            finalGeneral.setExclude(
-                                    new ExcludeBuilder()
-                                        .setSupportingServiceName(tmpExclude.getSupportingServiceName())
-                                        .setClli(tmpExclude.getSite())
-                                        .setNodeId(tmpExclude.getNodeId())
-                                        //.setAffinity(value)
-                                        //.setSRLG(value)
-                                        .build());
-                        }
-                        Include tmpInclude = tmpGeneral.getInclude();
-                        if (tmpInclude  !=  null) {
-                            finalGeneral.setInclude(
-                                    new IncludeBuilder()
-                                        //.setOrderedHops()
-                                        .build());
-                        }
-                        Latency tmpLatency = tmpGeneral.getLatency();
-                        if (tmpLatency  !=  null) {
-                            finalGeneral.setLatency(
-                                    new LatencyBuilder()
-                                        .setMaxLatency(tmpLatency.getMaxLatency())
-                                        .build());
-                        }
-                    }
-                    tempSoft
-                        .setCoRoutingOrGeneral(finalGeneral.build())
-                        .setCustomerCode(serviceSoftConstraints.getCustomerCode());
-                } else if (coRoutingOrGeneral instanceof CoRouting) {
-                    tmpCoRouting = (CoRouting)coRoutingOrGeneral;
-                    if (tmpCoRouting != null) {
-                        org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014
-                            .constraints.co.routing.or.general.co.routing.CoRouting tmpCoRoutingCoRouting =
-                            tmpCoRouting.getCoRouting();
-                        if (tmpCoRoutingCoRouting != null) {
-                            finalCoRouting.setCoRouting(
-                                    new CoRoutingBuilder()
-                                        .setExistingService(tmpCoRoutingCoRouting.getExistingService())
-                                        .build());
-                        }
-                    }
-                    tempSoft
-                        .setCoRoutingOrGeneral(finalCoRouting.build())
-                        .setCustomerCode(serviceSoftConstraints.getCustomerCode());
+        }
+        if (input instanceof HardConstraints) {
+            return tempHard.build();
+        } else if (input instanceof SoftConstraints) {
+            return tempSoft.build();
+        } else {
+            return null;
+        }
+    }
 
-                }
+    /**
+     * map hard/soft constraints from Service 1.2
+     * to ServicePath 1.4.
+     */
+    public void serviceToServicePathConstarints() {
+        LOG.info("Mapping Service Constraints to ServicePath Constraints");
+        if (serviceHardConstraints  !=  null) {
+            org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints
+                .rev171017.routing.constraints.sp.HardConstraints tempHard = (org.opendaylight.yang.gen
+                    .v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.routing
+                    .constraints.sp.HardConstraints) getConstraints(serviceHardConstraints);
+            if (tempHard != null) {
+                servicePathHardConstraints = tempHard;
+            }
+        } else if (serviceSoftConstraints  !=  null) {
+            org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints
+                .rev171017.routing.constraints.sp.SoftConstraints tempSoft = (org.opendaylight.yang.gen
+                    .v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.routing
+                    .constraints.sp.SoftConstraints) getConstraints(serviceSoftConstraints);
+            if (tempSoft != null) {
+                servicePathSoftConstraints = tempSoft;
             }
-            servicePathSoftConstraints = tempSoft.build();
         }
     }
 
@@ -263,25 +223,25 @@ public class MappingConstraints {
 
 
     public org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
-        .routing.constraints.rev170426.routing.constraints.sp.HardConstraints getServicePathHardConstraints() {
+        .routing.constraints.rev171017.routing.constraints.sp.HardConstraints getServicePathHardConstraints() {
         return servicePathHardConstraints;
     }
 
 
     public void setServicePathHardConstraints(org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
-            .routing.constraints.rev170426.routing.constraints.sp.HardConstraints servicePathHardConstraints) {
+            .routing.constraints.rev171017.routing.constraints.sp.HardConstraints servicePathHardConstraints) {
         this.servicePathHardConstraints = servicePathHardConstraints;
     }
 
 
     public org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
-        .routing.constraints.rev170426.routing.constraints.sp.SoftConstraints getServicePathSoftConstraints() {
+        .routing.constraints.rev171017.routing.constraints.sp.SoftConstraints getServicePathSoftConstraints() {
         return servicePathSoftConstraints;
     }
 
 
     public void setServicePathSoftConstraints(org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
-            .routing.constraints.rev170426.routing.constraints.sp.SoftConstraints servicePathSoftConstraints) {
+            .routing.constraints.rev171017.routing.constraints.sp.SoftConstraints servicePathSoftConstraints) {
         this.servicePathSoftConstraints = servicePathSoftConstraints;
     }