123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669 |
- <?php
- namespace Swagger\Client\Cablemodem;
- use Checks;
- use CurlOptions;
- use GuzzleHttp\Client;
- use Silex\Application;
- use Swagger\Client\ApiServices;
- use Swagger\Client\Base\Api\ValidationApi as ValidationApiBase;
- use Swagger\Client\Base\Configuration as ConfigurationBase;
- use Swagger\Client\Cablemodem\Api\CablemodemApi;
- use Swagger\Client\Cablemodem\Api\CablemodemModelApi;
- use Swagger\Client\Cablemodem\Api\NodeApi;
- use Swagger\Client\Cablemodem\Api\ProfileApi;
- use Swagger\Client\Cablemodem\Api\ValidationApi;
- use Swagger\Client\Cablemodem\Model\CablemodemCRUD;
- use Symfony\Component\HttpFoundation\Request;
- use Symfony\Component\HttpFoundation\Response;
- use Throwable;
- use Utils;
- class Services extends ApiServices
- {
- public function getNodeId(Application $app)
- {
- $app->get('/api/v1/cablemodem/node', function (Application $app, Request $request) {
- $ch = new Checks();
- $codeResponse = 400;
- try {
- $config = $this->setUserPasswordConfig($request, Configuration::getDefaultConfiguration());
- $apiInstance = new NodeApi(
- new Client(),
- $config
- );
- try {
- $id = $ch->integer($request, "id");
- $apiInstance->setDisabledTenancy(true);
- $result = $apiInstance->getById($id);
- $apiInstance->setDisabledTenancy(false);
- if ($result) {
- $content = $result->__toString();
- $content = (new CurlOptions())->clearNull($content);
- $codeResponse = 200;
- } else {
- $content = "No se encontro el id = " . $id;
- }
- } catch (Throwable $e) {
- $content = $e->getCode() . " - " . $e->getMessage();
- }
- } catch (Throwable $t) {
- $content = $t->getCode() . " - " . $t->getMessage();
- }
- return Utils::returnJSON($content, $codeResponse);
- });
- }
- public function getNodes(Application $app)
- {
- $app->get('/api/v1/cablemodem/nodes', function (Application $app, Request $request) {
- $ch = new Checks();
- $codeResponse = 400;
- try {
- $config = $this->setUserPasswordConfig($request, Configuration::getDefaultConfiguration());
- $apiInstance = new NodeApi(
- new Client(),
- $config
- );
- try {
- $page = $ch->integer($request, "page", false);
- $limit = $ch->integer($request, "limit", false);
- $id = $ch->integer($request, "id", false);
- $name = $ch->string($request, "name", false);
- $parent = $ch->integer($request, "parent", false);
- $tenancyId = $ch->integer($request, "tenancyId", false);
- $qb_criteria = $ch->integer($request, "qb-criteria", false, null);
- $content = "[";
- $result = $apiInstance->getList($id, $parent, $name, $tenancyId, $qb_criteria, $limit, $page);
- foreach ($result as $v) {
- // se eliminan los null
- $content .= $v->__toString() . ",";
- }
- if (strlen($content) > 1) {
- $content = substr($content, 0, strlen($content) - 1);
- }
- $content .= "]";
- $content = (new CurlOptions())->clearNull($content);
- $codeResponse = 200;
- } catch (Throwable $e) {
- $content = $e->getCode() . " - " . $e->getMessage();
- }
- } catch (Throwable $t) {
- $content = $t->getCode() . " - " . $t->getMessage();
- }
- return Utils::returnJSON($content, $codeResponse);
- });
- }
- public function getModelId(Application $app)
- {
- $app->get('/api/v1/cablemodem/model', function (Application $app, Request $request) {
- $ch = new Checks();
- $codeResponse = 400;
- try {
- $config = $this->setUserPasswordConfig($request, Configuration::getDefaultConfiguration());
- $apiInstance = new CablemodemModelApi(
- new Client(),
- $config
- );
- try {
- $id = $ch->integer($request, "id");
- $result = $apiInstance->getById($id);
- if ($result) {
- $content = $result->__toString();
- $content = (new CurlOptions())->clearNull($content);
- $codeResponse = 200;
- } else {
- $content = "No se encontro el id = " . $id;
- }
- } catch (Throwable $e) {
- $content = $e->getCode() . " - " . $e->getMessage();
- }
- } catch (Throwable $t) {
- $content = $t->getCode() . " - " . $t->getMessage();
- }
- return Utils::returnJSON($content, $codeResponse);
- });
- }
- public function getModels(Application $app)
- {
- $app->get('/api/v1/cablemodem/models', function (Application $app, Request $request) {
- $ch = new Checks();
- $codeResponse = 400;
- try {
- $config = $this->setUserPasswordConfig($request, Configuration::getDefaultConfiguration());
- $apiInstance = new CablemodemModelApi(
- new Client(),
- $config
- );
- try {
- $page = $ch->integer($request, "page", false);
- $limit = $ch->integer($request, "limit", false);
- $id = $ch->integer($request, "id", false);
- $name = $ch->string($request, "name", false);
- $qb_criteria = $ch->integer($request, "qb-criteria", false, null);
- $content = "[";
- $result = $apiInstance->getList($id, $name, $qb_criteria, $limit, $page);
- foreach ($result as $v) {
- // se eliminan los null
- $content .= $v->__toString() . ",";
- }
- if (strlen($content) > 1) {
- $content = substr($content, 0, strlen($content) - 1);
- }
- $content .= "]";
- $content = (new CurlOptions())->clearNull($content);
- $codeResponse = 200;
- } catch (Throwable $e) {
- $content = $e->getCode() . " - " . $e->getMessage();
- }
- } catch (Throwable $t) {
- $content = $t->getCode() . " - " . $t->getMessage();
- }
- return Utils::returnJSON($content, $codeResponse);
- });
- }
- public function getProfileId(Application $app)
- {
- $app->get('/api/v1/cablemodem/profile', function (Application $app, Request $request) {
- $ch = new Checks();
- $codeResponse = 400;
- try {
- $config = $this->setUserPasswordConfig($request, Configuration::getDefaultConfiguration());
- $apiInstance = new ProfileApi(
- new Client(),
- $config
- );
- try {
- $id = $ch->integer($request, "id");
- $apiInstance->setDisabledTenancy(true);
- $result = $apiInstance->getById($id);
- $apiInstance->setDisabledTenancy(false);
- if ($result) {
- $content = $result->__toString();
- $content = (new CurlOptions())->clearNull($content);
- $codeResponse = 200;
- } else {
- $content = "No se encontro el id = " . $id;
- }
- } catch (Throwable $e) {
- $content = $e->getCode() . " - " . $e->getMessage();
- }
- } catch (Throwable $t) {
- $content = $t->getCode() . " - " . $t->getMessage();
- }
- return Utils::returnJSON($content, $codeResponse);
- });
- }
- public function getProfiles(Application $app)
- {
- $app->get('/api/v1/cablemodem/profiles', function (Application $app, Request $request) {
- $ch = new Checks();
- $codeResponse = 400;
- try {
- $config = $this->setUserPasswordConfig($request, Configuration::getDefaultConfiguration());
- $apiInstance = new ProfileApi(
- new Client(),
- $config
- );
- try {
- $page = $ch->integer($request, "page", false);
- $limit = $ch->integer($request, "limit", false);
- $id = $ch->integer($request, "id", false);
- $name = $ch->string($request, "name", false);
- $downstream = $ch->integer($request, "downstream", false);
- $upstream = $ch->integer($request, "upstream", false);
- $upload = $ch->integer($request, "upload", false);
- $download = $ch->integer($request, "download", false);
- $maxcpe = $ch->integer($request, "maxcpe", false);
- $tenancyId = $ch->integer($request, "tenancyId", false);
- $qb_criteria = $ch->integer($request, "qb-criteria", false, null);
- $content = "[";
- $result = $apiInstance->getList($id, $name, $downstream, $upstream, $upload, $download, $maxcpe, $tenancyId, $qb_criteria, $limit, $page);
- foreach ($result as $v) {
- // se eliminan los null
- $content .= $v->__toString() . ",";
- }
- if (strlen($content) > 1) {
- $content = substr($content, 0, strlen($content) - 1);
- }
- $content .= "]";
- $content = (new CurlOptions())->clearNull($content);
- $codeResponse = 200;
- } catch (Throwable $e) {
- $content = $e->getCode() . " - " . $e->getMessage();
- }
- } catch (Throwable $t) {
- $content = $t->getCode() . " - " . $t->getMessage();
- }
- return Utils::returnJSON($content, $codeResponse);
- });
- }
- public function getCablemodemId(Application $app)
- {
- $app->get('/api/v1/cablemodem/cablemodem', function (Application $app, Request $request) {
- $ch = new Checks();
- $codeResponse = 400;
- try {
- $config = $this->setUserPasswordConfig($request, Configuration::getDefaultConfiguration());
- $apiInstance = new CablemodemApi(
- new Client(),
- $config
- );
- try {
- $id = $ch->integer($request, "id");
- $apiInstance->setDisabledTenancy(true);
- $result = $apiInstance->getById($id);
- $apiInstance->setDisabledTenancy(false);
- if ($result) {
- $content = $result->__toString();
- $content = (new CurlOptions())->clearNull($content);
- $codeResponse = 200;
- } else {
- $content = "No se encontro el id = " . $id;
- }
- } catch (Throwable $e) {
- $content = $e->getCode() . " - " . $e->getMessage();
- }
- } catch (Throwable $t) {
- $content = $t->getCode() . " - " . $t->getMessage();
- }
- return Utils::returnJSON($content, $codeResponse);
- });
- }
- public function getCablemodems(Application $app)
- {
- $app->get('/api/v1/cablemodem/cablemodems', function (Application $app, Request $request) {
- $ch = new Checks();
- $codeResponse = 400;
- try {
- $config = $this->setUserPasswordConfig($request, Configuration::getDefaultConfiguration());
- $apiInstance = new CablemodemApi(
- new Client(),
- $config
- );
- try {
- $page = $ch->integer($request, "page", false);
- $limit = $ch->integer($request, "limit", false);
- $id = $ch->integer($request, "id", false);
- $clientId = $ch->string($request, "clientId", false);
- $mac = $ch->integer($request, "mac", false);
- $node = $ch->string($request, "node", false);
- $profile = $ch->string($request, "profiel", false);
- $model = $ch->string($request, "model", false);
- $tenancyId = $ch->integer($request, "tenancyId", false);
- $qb_criteria = $ch->integer($request, "qb-criteria", false, null);
- $content = "[";
- $result = $apiInstance->getList($id, $clientId, $mac, $node, $profile, $model, $tenancyId, $qb_criteria, $limit, $page);
- foreach ($result as $v) {
- // se eliminan los null
- $content .= $v->__toString() . ",";
- }
- if (strlen($content) > 1) {
- $content = substr($content, 0, strlen($content) - 1);
- }
- $content .= "]";
- $content = (new CurlOptions())->clearNull($content);
- $codeResponse = 200;
- } catch (Throwable $e) {
- $content = $e->getCode() . " - " . $e->getMessage();
- }
- } catch (Throwable $t) {
- $content = $t->getCode() . " - " . $t->getMessage();
- }
- return Utils::returnJSON($content, $codeResponse);
- });
- }
- public function postCablemodem(Application $app)
- {
- $app->post('/api/v1/cablemodem/cablemodem', function (Application $app, Request $request) {
- $codeResponse = 400;
- try {
- $config = $this->setUserPasswordConfig($request, Configuration::getDefaultConfiguration());
- $configBase = $this->setUserPasswordConfig($request, ConfigurationBase::getDefaultConfiguration());
- $apiInstance = new CablemodemApi(
- new Client(),
- $config
- );
- $data = json_decode(file_get_contents('php://input'), true);
- $utils = new Utils();
- $instance = $utils->loadData(new CablemodemCRUD(), $data);
- $errors = $instance->listInvalidProperties();
- if (is_null($instance->getMac()) || trim($instance->getMac()) == "") {
- $content = "Debe cargar la mac del cablemodem.";
- } elseif (preg_match('/([a-fA-F0-9]{2}[:|\-]?){6}/', trim($instance->getMac())) == 0) {
- $content = "La mac es incorrecta.";
- } elseif (is_null($instance->getProfile()) ||
- !is_numeric($instance->getProfile()) ||
- $instance->getProfile() <= 0) {
- $content = "Debe cargar el perfil del cablemodem.";
- } elseif (count($errors) === 0) {
- // chequeo la tenencia
- $apiValidationBase = new ValidationApiBase(
- new Client(),
- $configBase
- );
- $apiValidationCablemodem = new ValidationApi(
- new Client(),
- $config
- );
- $content = null;
- // verifico si existe la tenencia
- if ($apiValidationBase->validTenancy($instance->getTenancyId())) {
- if (!is_null($instance->getClientId()) && $instance->getClientId() > 0) {
- // chequeo el cliente exista
- if (!$apiValidationBase->validClient($instance->getClientId())) {
- $content = "El id del cliente no existe.";
- }
- }
- if (is_null($content)) {
- // mostrar error de que la mac ya existe
- $result = $apiValidationCablemodem->existsCablemodem($instance->getMac(), $instance->getTenancyId());
- $name = "";
- if ($result) {
- $name = $result->getId() . " - " . $result->getMac();
- }
- if ($name == "") {
- if (!is_null($instance->getNode())) {
- if (!$apiValidationCablemodem->validNode($instance->getNode())) {
- $content = "El id de nodo no existe.";
- }
- }
- if (is_null($content)) {
- if (!is_null($instance->getProfile())) {
- if (!$apiValidationCablemodem->validProfile($instance->getProfile())) {
- $content = "El id del profile no existe.";
- }
- }
- if (is_null($content)) {
- if (!is_null($instance->getModel())) {
- if (!$apiValidationCablemodem->validCablemodemModel($instance->getModel())) {
- $content = "El id del modelo no existe.";
- }
- }
- if (is_null($content)) {
- $apiInstance->create($instance);
- // busco el id del cliente, buscandolo por mac
- $result = $apiValidationCablemodem->existsCablemodem($instance->getMac(), $instance->getTenancyId());
- if ($result) {
- $content = $result->__toString();
- $codeResponse = 200;
- } else {
- $content = "No se pudo obtener el cablemodem cargado. Verifique por sistema si la carga se realizo correctamente.";
- }
- }
- }
- }
- } else {
- $codeResponse = 409;
- $content = "La MAC ya existe y pertenece al cablemodem " . $name . ".";
- }
- }
- } else {
- $content = "El id de tenencia es incorrecto.";
- }
- } else {
- $content = json_encode($errors);
- }
- } catch (Throwable $t) {
- $content = $t->getCode() . " - " . $t->getMessage();
- }
- return Utils::returnJSON($content, $codeResponse);
- });
- }
- public function putCablemodem(Application $app)
- {
- $app->put('/api/v1/cablemodem/cablemodem', function (Application $app, Request $request) {
- $codeResponse = 400;
- try {
- $config = $this->setUserPasswordConfig($request, Configuration::getDefaultConfiguration());
- $configBase = $this->setUserPasswordConfig($request, ConfigurationBase::getDefaultConfiguration());
- $apiInstance = new CablemodemApi(
- new Client(),
- $config
- );
- $data = json_decode(file_get_contents('php://input'), true);
- $utils = new Utils();
- $instance = $utils->loadData(new CablemodemCRUD(), $data);
- $errors = $instance->listInvalidProperties();
- if (is_null($instance->getMac()) || trim($instance->getMac()) == "") {
- $content = "Debe cargar la mac del cablemodem.";
- } elseif (is_null($instance->getProfile()) ||
- !is_numeric($instance->getProfile()) ||
- $instance->getProfile() <= 0) {
- $content = "Debe cargar el perfil del cablemodem.";
- } elseif (count($errors) === 0) {
- // chequeo la tenencia
- $apiValidationBase = new ValidationApiBase(
- new Client(),
- $configBase
- );
- $apiValidationCablemodem = new ValidationApi(
- new Client(),
- $config
- );
- $content = null;
- // verifico si existe la tenencia
- if ($apiValidationBase->validTenancy($instance->getTenancyId())) {
- if (!is_null($instance->getClientId()) && $instance->getClientId() > 0) {
- // chequeo el cliente exista
- if (!$apiValidationBase->validClient($instance->getClientId())) {
- $content = "El id del cliente no existe.";
- }
- }
- if (is_null($content)) {
- // mostrar error de que la mac ya existe
- $result = $apiValidationCablemodem->existsCablemodem($instance->getMac(), $instance->getTenancyId());
- $name = "";
- if ($result && $result->getId() != $instance->getId()) {
- $name = $result->getId() . " - " . $result->getMac();
- }
- if ($name == "") {
- if (!is_null($instance->getNode())) {
- if (!$apiValidationCablemodem->validNode($instance->getNode())) {
- $content = "El id de nodo no existe.";
- }
- }
- if (is_null($content)) {
- if (!is_null($instance->getProfile())) {
- if (!$apiValidationCablemodem->validProfile($instance->getProfile())) {
- $content = "El id del profile no existe.";
- }
- }
- if (is_null($content)) {
- if (!is_null($instance->getModel())) {
- if (!$apiValidationCablemodem->validCablemodemModel($instance->getModel())) {
- $content = "El id del modelo no existe.";
- }
- }
- if (is_null($content)) {
- $apiInstance->update($instance->getId(), $instance);
- // busco el id del cliente, buscandolo por externalid
- $apiInstance->setDisabledTenancy(true);
- $result = $apiInstance->getById($instance->getId());
- $apiInstance->setDisabledTenancy(false);
- if ($result) {
- $content = $result->__toString();
- $codeResponse = 200;
- } else {
- $content = "No se pudo obtener el cablemodem cargado. Verifique por sistema si la carga se realizo correctamente.";
- }
- }
- }
- }
- } else {
- $codeResponse = 409;
- $content = "La MAC ya existe y pertenece al cablemodem " . $name . ".";
- }
- }
- } else {
- $content = "El id de tenencia es incorrecto.";
- }
- } else {
- $content = json_encode($errors);
- }
- } catch (Throwable $t) {
- $content = $t->getCode() . " - " . $t->getMessage();
- }
- return Utils::returnJSON($content, $codeResponse);
- });
- }
- public function deleteCablemodem(Application $app)
- {
- $app->delete('/api/v1/cablemodem/cablemodem', function (Application $app, Request $request) {
- $codeResponse = 400;
- try {
- $config = $this->setUserPasswordConfig($request, Configuration::getDefaultConfiguration());
- $apiInstance = new CablemodemApi(
- new Client(),
- $config
- );
- $ch = new Checks();
- $id = $ch->integer($request, "id", true);
- $apiInstance->setDisabledTenancy(true);
- $result = $apiInstance->getById($id);
- $apiInstance->setDisabledTenancy(false);
- if (!is_null($result)) {
- $apiInstance->delete($id);
- $content = $result->__toString();
- $codeResponse = 200;
- } else {
- $content = "No se encontro el id = " . $id;
- }
- } catch (Throwable $t) {
- $content = $t->getCode() . " - " . $t->getMessage();
- }
- return Utils::returnJSON($content, $codeResponse);
- });
- }
- public function getCablemodemActive(Application $app)
- {
- $app->get('/api/v1/cablemodem/cablemodem/active', function (Application $app, Request $request) {
- $codeResponse = 400;
- try {
- $config = $this->setUserPasswordConfig($request, Configuration::getDefaultConfiguration());
- $apiInstance = new CablemodemApi(
- new Client(),
- $config
- );
- $ch = new Checks();
- $id = $ch->integer($request, "id", true);
- $workflow = "administrative_state";
- $transition = "suspend_to_active";
- $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 el cablemodem de id = " . $id;
- }
- } catch (Throwable $t) {
- $content = $t->getCode() . " - " . $t->getMessage();
- }
- return Utils::returnJSON($content, $codeResponse);
- });
- }
- public function getCablemodemDisable(Application $app)
- {
- $app->get('/api/v1/cablemodem/cablemodem/disable', function (Application $app, Request $request) {
- $codeResponse = 400;
- try {
- $config = $this->setUserPasswordConfig($request, Configuration::getDefaultConfiguration());
- $apiInstance = new CablemodemApi(
- new Client(),
- $config
- );
- $ch = new Checks();
- $id = $ch->integer($request, "id", true);
- $workflow = "administrative_state";
- $transition = "active_to_suspend";
- $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 el cablemodem de id = " . $id;
- }
- } catch (Throwable $t) {
- $content = $t->getCode() . " - " . $t->getMessage();
- }
- return Utils::returnJSON($content, $codeResponse);
- });
- }
- public function getCablemodemSupply(Application $app)
- {
- $app->get('/api/v1/cablemodem/cablemodem/supply', function (Application $app, Request $request) {
- $codeResponse = 400;
- try {
- $config = $this->setUserPasswordConfig($request, Configuration::getDefaultConfiguration());
- $apiInstance = new CablemodemApi(
- new Client(),
- $config
- );
- $ch = new Checks();
- $mac = $ch->string($request, "mac", true);
- $activationCode = $ch->string($request, "activationCode", true);
- $apiInstance->setDisabledTenancy(true);
- $result = $apiInstance->getList(null, null, $mac);
- $apiInstance->setDisabledTenancy(false);
- $util = new \Utils();
- $result = $util->valueExistsLower($mac,
- $result,
- "getMac");
- if (!is_null($result)) {
- $instance = new CablemodemCRUD();
- $instance->setId($result->getId());
- $instance->setActivationCode($activationCode);
- $apiInstance->update($result->getId(), $instance);
- $apiInstance->setDisabledTenancy(true);
- $result = $apiInstance->getById($result->getId());
- $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 el cablemodem de mac = " . $mac;
- }
- } catch (Throwable $t) {
- $content = $t->getCode() . " - " . $t->getMessage();
- }
- return Utils::returnJSON($content, $codeResponse);
- });
- }
- }
|