Prechádzať zdrojové kódy

Ref #14. Now we can filter, create and update catv in the ONU using values true or
false.

Maximiliano Schvindt 5 rokov pred
rodič
commit
44e43f3720

+ 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);
+    }
 
 
 }

+ 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.";
+                                                                        }
                                                                     }
                                                                 }
                                                             }