Forráskód Böngészése

Update from extra

gabriel 6 éve
szülő
commit
b0663a1c6f

+ 5 - 0
src/Swagger/Client/ApiServices.php

@@ -14,9 +14,14 @@ class ApiServices
      */
     protected function setUserPasswordConfig(Request $request, ConfigurationInterface $config)
     {
+        if ($request->headers->get("php-auth-user") &&
+            $request->headers->get("php-auth-pw")) {
         $config
             ->setUsername($request->headers->get("php-auth-user"))
             ->setPassword($request->headers->get("php-auth-pw"));
+        } else {
+            throw new \Exception ("Debe ingresar un usuario y password.");
+        }
         return $config;
     }
 }

+ 79 - 4
src/Swagger/Client/FTTH/Services.php

@@ -1013,8 +1013,8 @@ class Services extends ApiServices
                 );
                 $ch = new Checks();
                 $id = $ch->integer($request, "id", true);
-                $workflow = "administrative_state";
-                $transition = "suspend_to_active";
+                $workflow = "onu_workflow_2";
+                $transition = "active";
                 $apiInstance->setDisabledTenancy(true);
                 $result = $apiInstance->getById($id);
                 $apiInstance->setDisabledTenancy(false);
@@ -1039,6 +1039,43 @@ class Services extends ApiServices
         });
     }
 
+    public function getONUSuspend(Application $app)
+    {
+        $app->get('/api/v1/ftth/onu/suspend', function (Application $app, Request $request) {
+            $codeResponse = 400;
+            try {
+                $config = $this->setUserPasswordConfig($request, Configuration::getDefaultConfiguration());
+                $apiInstance = new ONUApi(
+                    new Client(),
+                    $config
+                );
+                $ch = new Checks();
+                $id = $ch->integer($request, "id", true);
+                $workflow = "onu_workflow_2";
+                $transition = "disable_delete";
+                $apiInstance->setDisabledTenancy(true);
+                $result = $apiInstance->getById($id);
+                $apiInstance->setDisabledTenancy(false);
+                if (!is_null($result)) {
+                    $apiInstance->apply($id, $workflow, $transition);
+                    $apiInstance->setDisabledTenancy(true);
+                    $result = $apiInstance->getById($id);
+                    $apiInstance->setDisabledTenancy(false);
+                    if ($result) {
+                        $content = $result->__toString();
+                        $codeResponse = 200;
+                    } else {
+                        $content = "No se pudo obtener el acceso cargado. Verifique por sistema si la carga se realizo correctamente.";
+                    }
+                } else {
+                    $content = "No se encontro la onu de id = " . $id;
+                }
+            } catch (Throwable $t) {
+                $content = $t->getCode() . " - " . $t->getMessage();
+            }
+            return new Response($content, $codeResponse);
+        });
+    }
     public function getONUDisable(Application $app)
     {
         $app->get('/api/v1/ftth/onu/disable', function (Application $app, Request $request) {
@@ -1051,8 +1088,46 @@ class Services extends ApiServices
                 );
                 $ch = new Checks();
                 $id = $ch->integer($request, "id", true);
-                $workflow = "administrative_state";
-                $transition = "active_to_suspend";
+                $workflow = "onu_workflow_2";
+                $transition = "disable";
+                $apiInstance->setDisabledTenancy(true);
+                $result = $apiInstance->getById($id);
+                $apiInstance->setDisabledTenancy(false);
+                if (!is_null($result)) {
+                    $apiInstance->apply($id, $workflow, $transition);
+                    $apiInstance->setDisabledTenancy(true);
+                    $result = $apiInstance->getById($id);
+                    $apiInstance->setDisabledTenancy(false);
+                    if ($result) {
+                        $content = $result->__toString();
+                        $codeResponse = 200;
+                    } else {
+                        $content = "No se pudo obtener el acceso cargado. Verifique por sistema si la carga se realizo correctamente.";
+                    }
+                } else {
+                    $content = "No se encontro la onu de id = " . $id;
+                }
+            } catch (Throwable $t) {
+                $content = $t->getCode() . " - " . $t->getMessage();
+            }
+            return new Response($content, $codeResponse);
+        });
+    }
+
+    public function getONUEnable(Application $app)
+    {
+        $app->get('/api/v1/ftth/onu/enable', function (Application $app, Request $request) {
+            $codeResponse = 400;
+            try {
+                $config = $this->setUserPasswordConfig($request, Configuration::getDefaultConfiguration());
+                $apiInstance = new ONUApi(
+                    new Client(),
+                    $config
+                );
+                $ch = new Checks();
+                $id = $ch->integer($request, "id", true);
+                $workflow = "onu_workflow_2";
+                $transition = "active";
                 $apiInstance->setDisabledTenancy(true);
                 $result = $apiInstance->getById($id);
                 $apiInstance->setDisabledTenancy(false);

+ 2 - 0
src/app.php

@@ -77,6 +77,8 @@ $ftth->postONU($app);
 $ftth->putONU($app);
 $ftth->deleteONU($app);
 $ftth->getONUActive($app);
+$ftth->getONUSuspend($app);
+$ftth->getONUEnable($app);
 $ftth->getONUDisable($app);
 $ftth->getONUSupply($app);