Преглед на файлове

Merge branch 'api#13' into 'master'

Api#13

See merge request interlink-sa/flowdat3/modules/api!2
Maximiliano Schvindt преди 5 години
родител
ревизия
ff04b48e8e

+ 38 - 0
src/Checks.php

@@ -94,4 +94,42 @@ class Checks
         }
         return $value;
     }
+
+    /**
+     * Throws exception if not boolean.
+     * @param Request|array $all Contains array with query.
+     * @param string $property Contains the name of property
+     * @param boolean $required Check if property exists in request
+     * @param mixed $default Default value.
+     * @return integer Return integer 0, 1 or null.
+     * @throws Error Throws errors.
+     */
+    function boolean($all, $property, $required = true, $default = null)
+    {
+        if ($all != null) {
+            if ($all instanceof Request) {
+                $all = $all->query->all();
+            }
+            $key_exists = array_key_exists($property, $all);
+            if (!$key_exists && $default != null) {
+                $all[$property] = $default;
+                $key_exists = true;
+            }
+            if (!$key_exists) {
+                if ($required) {
+                    throw (new Errors())->errorRequired($property, "boolean");
+                } else {
+                    // value not exists
+                    return null;
+                }
+            } else if (is_bool($all[$property]) || in_array(strtolower($all[$property]),['true','false','0','1'])) {
+                $bool = filter_var( $all[$property], FILTER_VALIDATE_BOOLEAN );
+                return (int)$bool;
+            } else {
+                throw (new Errors())->errorBoolean($property);
+            }
+        } else {
+            return null;
+        }
+    }
 }

+ 3 - 1
src/CurlOptions.php

@@ -67,7 +67,9 @@ class CurlOptions
     {
         if ($resp && is_array($resp)) {
             foreach ($resp as $key => $value) {
-                if (is_null($value) ||
+                if(is_bool($value)) {
+                    $resp[$key] = (boolean) $value;
+                } else if (is_null($value) ||
                     $value == null ||
                     $value == "null" ||
                     $value == "NULL") {

+ 9 - 0
src/Errors.php

@@ -47,6 +47,15 @@ class Errors
     {
         return new Error("Incorrect " . $property . ". Only support integer.", 100002);
     }
+    
+    /**
+     * @param string $property Contains the name of property
+     * @return Error Throws errors.
+     */
+    function errorBoolean($property)
+    {
+        return new Error("Incorrect " . $property . ". Only support boolean.", 100002);
+    }
 
 
 }

+ 2 - 2
src/Swagger/Client/Base/Model/Client.php

@@ -202,7 +202,7 @@ class Client implements ModelInterface, ArrayAccess
     const CURRENT_STATE_ACTIVE = 'active';
     const CURRENT_STATE_PRE_NOTICE = 'pre_notice';
     const CURRENT_STATE_SUSPEND = 'suspend';
-    const CURRENT_STATE_CANCELED = 'canceled';
+    const CURRENT_STATE_CANCELLED = 'cancelled';
     const CURRENT_STATE_NOT_PROVISIONED = 'not_provisioned';
     const CURRENT_STATE_DELETED = 'deleted';
 
@@ -220,7 +220,7 @@ class Client implements ModelInterface, ArrayAccess
             self::CURRENT_STATE_ACTIVE,
             self::CURRENT_STATE_PRE_NOTICE,
             self::CURRENT_STATE_SUSPEND,
-            self::CURRENT_STATE_CANCELED,
+            self::CURRENT_STATE_CANCELLED,
             self::CURRENT_STATE_NOT_PROVISIONED,
             self::CURRENT_STATE_DELETED
         ];

+ 2 - 2
src/Swagger/Client/Base/Services.php

@@ -329,7 +329,7 @@ class Services extends ApiServices
                 $ch = new Checks();
                 $id = $ch->integer($request, "id");
                 $workflow = "administrative_state";
-                $transition = "active_to_suspend";
+                $transition = "suspend";
 
                 $apiInstance->setDisabledTenancy(true);
                 $result = $apiInstance->getById($id);
@@ -369,7 +369,7 @@ class Services extends ApiServices
                 $ch = new Checks();
                 $id = $ch->integer($request, "id");
                 $workflow = "administrative_state";
-                $transition = "suspend_to_active";
+                $transition = "active";
 
                 $apiInstance->setDisabledTenancy(true);
                 $result = $apiInstance->getById($id);

+ 1 - 1
src/Swagger/Client/FTTH/Model/ONU.php

@@ -76,7 +76,7 @@ class ONU implements ModelInterface, ArrayAccess
         'service_ports' => 'object[]',
         'traffic_profile_out' => '\Swagger\Client\FTTH\Model\TrafficProfile',
         'traffic_profile_in' => '\Swagger\Client\FTTH\Model\TrafficProfile',
-        'catv' => 'int',
+        'catv' => 'bool',
         'olt' => '\Swagger\Client\FTTH\Model\OLT',
         'position' => 'int',
         'client_id' => 'int',

+ 3 - 3
src/Swagger/Client/FTTH/Model/ONUCRUD.php

@@ -73,7 +73,7 @@ class ONUCRUD implements ModelInterface, ArrayAccess
         'vlan' => 'int',
         'traffic_profile_out' => 'int',
         'traffic_profile_in' => 'int',
-        'catv' => 'int',
+        'catv' => 'bool',
         'olt' => 'int',
         'position' => 'int',
         'client_id' => 'int',
@@ -680,7 +680,7 @@ class ONUCRUD implements ModelInterface, ArrayAccess
     /**
      * Gets catv
      *
-     * @return int
+     * @return boolean
      */
     public function getCatv()
     {
@@ -690,7 +690,7 @@ class ONUCRUD implements ModelInterface, ArrayAccess
     /**
      * Sets catv
      *
-     * @param int $catv Si esta en 1 significa que posee catv.
+     * @param boolean $catv Si esta en 1 significa que posee catv.
      *
      * @return $this
      */

+ 1 - 1
src/Swagger/Client/FTTH/Model/ONUTemplate.php

@@ -69,7 +69,7 @@ class ONUTemplate implements ModelInterface, ArrayAccess
         'vlan_profile' => '\Swagger\Client\FTTH\Model\VLanProfile',
         'onu_profile' => '\Swagger\Client\FTTH\Model\ONUProfile',
         'base' => 'int',
-        'catv' => 'int',
+        'catv' => 'boolean',
         'tenancy_id' => 'int'
     ];
 

+ 24 - 9
src/Swagger/Client/FTTH/Services.php

@@ -615,7 +615,7 @@ class Services extends ApiServices
                     $vlan = $ch->integer($request, "vlan", false);
                     $trafficProfileOut = $ch->integer($request, "trafficProfileOut", false);
                     $trafficProfileIn = $ch->integer($request, "trafficProfileIn", false);
-                    $catv = $ch->integer($request, "catv", false);
+                    $catv = $ch->boolean($request, "catv", false);
                     $content = "[";
                     $result = $apiInstance->getList($id, $clientId, $ponSerialNumber, $currentState, $profile, $nap, $onuProfile, $vlanProfile, $model, $serialNumber, $ponSerialNumberAux, $position, $ip, $mac, $vlan, $trafficProfileOut, $trafficProfileIn, $catv, $olt, $tenancyId, $qb_criteria, $limit, $page);
                     foreach ($result as $v) {
@@ -743,6 +743,12 @@ class Services extends ApiServices
                                     $instance->setTrafficProfileIn($onuTemplate->getTrafficProfileIn()->getId());
                                 }
                             }
+                            if (is_null($instance->getCatv()) || !is_bool($instance->getCatv())) {
+                                // catv = true or false
+                                if (!is_null($onuTemplate->getCatv()))  {
+                                    $instance->setCatv($onuTemplate->getCatv());
+                                }
+                            }
                         }
                     }
                     // chequeo la tenencia
@@ -828,14 +834,23 @@ class Services extends ApiServices
                                                                     }
                                                                 }
                                                                 if (is_null($content)) {
-                                                                    $apiInstance->create($instance);
-                                                                    // busco el id del cliente, buscandolo por externalid
-                                                                    $result = $apiValidationFTTH->existsONU($instance->getPonSerialNumber(), $instance->getTenancyId());
-                                                                    if ($result) {
-                                                                        $content = $result->__toString();
-                                                                        $codeResponse = 200;
-                                                                    } else {
-                                                                        $content = "No se pudo obtener la ONU cargada. Verifique por sistema si la carga se realizo correctamente.";
+                                                                    if (!is_null($instance->getCatv())) {
+                                                                        if (!is_bool($instance->getCatv())) {
+                                                                            $content = "El CATV deber ser true or false.";
+                                                                        }
+                                                                    }
+                                                                    if (is_null($content)) {
+                                                                        //print_r($instance);
+                                                                        //die;
+                                                                        $apiInstance->create($instance);
+                                                                        // busco el id del cliente, buscandolo por externalid
+                                                                        $result = $apiValidationFTTH->existsONU($instance->getPonSerialNumber(), $instance->getTenancyId());
+                                                                        if ($result) {
+                                                                            $content = $result->__toString();
+                                                                            $codeResponse = 200;
+                                                                        } else {
+                                                                            $content = "No se pudo obtener la ONU cargada. Verifique por sistema si la carga se realizo correctamente.";
+                                                                        }
                                                                     }
                                                                 }
                                                             }