Services.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  1. <?php
  2. namespace Swagger\Client\Cablemodem;
  3. use Checks;
  4. use CurlOptions;
  5. use GuzzleHttp\Client;
  6. use Silex\Application;
  7. use Swagger\Client\ApiServices;
  8. use Swagger\Client\Base\Api\ValidationApi as ValidationApiBase;
  9. use Swagger\Client\Base\Configuration as ConfigurationBase;
  10. use Swagger\Client\Cablemodem\Api\CablemodemApi;
  11. use Swagger\Client\Cablemodem\Api\CablemodemModelApi;
  12. use Swagger\Client\Cablemodem\Api\NodeApi;
  13. use Swagger\Client\Cablemodem\Api\ProfileApi;
  14. use Swagger\Client\Cablemodem\Api\ValidationApi;
  15. use Swagger\Client\Cablemodem\Model\CablemodemCRUD;
  16. use Symfony\Component\HttpFoundation\Request;
  17. use Symfony\Component\HttpFoundation\Response;
  18. use Throwable;
  19. use Utils;
  20. class Services extends ApiServices
  21. {
  22. public function getNodeId(Application $app)
  23. {
  24. $app->get('/api/v1/cablemodem/node', function (Application $app, Request $request) {
  25. $ch = new Checks();
  26. $codeResponse = 400;
  27. try {
  28. $config = $this->setUserPasswordConfig($request, Configuration::getDefaultConfiguration());
  29. $apiInstance = new NodeApi(
  30. new Client(),
  31. $config
  32. );
  33. try {
  34. $id = $ch->integer($request, "id");
  35. $apiInstance->setDisabledTenancy(true);
  36. $result = $apiInstance->getById($id);
  37. $apiInstance->setDisabledTenancy(false);
  38. if ($result) {
  39. $content = $result->__toString();
  40. $content = (new CurlOptions())->clearNull($content);
  41. $codeResponse = 200;
  42. } else {
  43. $content = "No se encontro el id = " . $id;
  44. }
  45. } catch (Throwable $e) {
  46. $content = $e->getCode() . " - " . $e->getMessage();
  47. }
  48. } catch (Throwable $t) {
  49. $content = $t->getCode() . " - " . $t->getMessage();
  50. }
  51. return Utils::returnJSON($content, $codeResponse);
  52. });
  53. }
  54. public function getNodes(Application $app)
  55. {
  56. $app->get('/api/v1/cablemodem/nodes', function (Application $app, Request $request) {
  57. $ch = new Checks();
  58. $codeResponse = 400;
  59. try {
  60. $config = $this->setUserPasswordConfig($request, Configuration::getDefaultConfiguration());
  61. $apiInstance = new NodeApi(
  62. new Client(),
  63. $config
  64. );
  65. try {
  66. $page = $ch->integer($request, "page", false);
  67. $limit = $ch->integer($request, "limit", false);
  68. $id = $ch->integer($request, "id", false);
  69. $name = $ch->string($request, "name", false);
  70. $parent = $ch->integer($request, "parent", false);
  71. $tenancyId = $ch->integer($request, "tenancyId", false);
  72. $qb_criteria = $ch->integer($request, "qb-criteria", false, null);
  73. $content = "[";
  74. $result = $apiInstance->getList($id, $parent, $name, $tenancyId, $qb_criteria, $limit, $page);
  75. foreach ($result as $v) {
  76. // se eliminan los null
  77. $content .= $v->__toString() . ",";
  78. }
  79. if (strlen($content) > 1) {
  80. $content = substr($content, 0, strlen($content) - 1);
  81. }
  82. $content .= "]";
  83. $content = (new CurlOptions())->clearNull($content);
  84. $codeResponse = 200;
  85. } catch (Throwable $e) {
  86. $content = $e->getCode() . " - " . $e->getMessage();
  87. }
  88. } catch (Throwable $t) {
  89. $content = $t->getCode() . " - " . $t->getMessage();
  90. }
  91. return Utils::returnJSON($content, $codeResponse);
  92. });
  93. }
  94. public function getModelId(Application $app)
  95. {
  96. $app->get('/api/v1/cablemodem/model', function (Application $app, Request $request) {
  97. $ch = new Checks();
  98. $codeResponse = 400;
  99. try {
  100. $config = $this->setUserPasswordConfig($request, Configuration::getDefaultConfiguration());
  101. $apiInstance = new CablemodemModelApi(
  102. new Client(),
  103. $config
  104. );
  105. try {
  106. $id = $ch->integer($request, "id");
  107. $result = $apiInstance->getById($id);
  108. if ($result) {
  109. $content = $result->__toString();
  110. $content = (new CurlOptions())->clearNull($content);
  111. $codeResponse = 200;
  112. } else {
  113. $content = "No se encontro el id = " . $id;
  114. }
  115. } catch (Throwable $e) {
  116. $content = $e->getCode() . " - " . $e->getMessage();
  117. }
  118. } catch (Throwable $t) {
  119. $content = $t->getCode() . " - " . $t->getMessage();
  120. }
  121. return Utils::returnJSON($content, $codeResponse);
  122. });
  123. }
  124. public function getModels(Application $app)
  125. {
  126. $app->get('/api/v1/cablemodem/models', function (Application $app, Request $request) {
  127. $ch = new Checks();
  128. $codeResponse = 400;
  129. try {
  130. $config = $this->setUserPasswordConfig($request, Configuration::getDefaultConfiguration());
  131. $apiInstance = new CablemodemModelApi(
  132. new Client(),
  133. $config
  134. );
  135. try {
  136. $page = $ch->integer($request, "page", false);
  137. $limit = $ch->integer($request, "limit", false);
  138. $id = $ch->integer($request, "id", false);
  139. $name = $ch->string($request, "name", false);
  140. $qb_criteria = $ch->integer($request, "qb-criteria", false, null);
  141. $content = "[";
  142. $result = $apiInstance->getList($id, $name, $qb_criteria, $limit, $page);
  143. foreach ($result as $v) {
  144. // se eliminan los null
  145. $content .= $v->__toString() . ",";
  146. }
  147. if (strlen($content) > 1) {
  148. $content = substr($content, 0, strlen($content) - 1);
  149. }
  150. $content .= "]";
  151. $content = (new CurlOptions())->clearNull($content);
  152. $codeResponse = 200;
  153. } catch (Throwable $e) {
  154. $content = $e->getCode() . " - " . $e->getMessage();
  155. }
  156. } catch (Throwable $t) {
  157. $content = $t->getCode() . " - " . $t->getMessage();
  158. }
  159. return Utils::returnJSON($content, $codeResponse);
  160. });
  161. }
  162. public function getProfileId(Application $app)
  163. {
  164. $app->get('/api/v1/cablemodem/profile', function (Application $app, Request $request) {
  165. $ch = new Checks();
  166. $codeResponse = 400;
  167. try {
  168. $config = $this->setUserPasswordConfig($request, Configuration::getDefaultConfiguration());
  169. $apiInstance = new ProfileApi(
  170. new Client(),
  171. $config
  172. );
  173. try {
  174. $id = $ch->integer($request, "id");
  175. $apiInstance->setDisabledTenancy(true);
  176. $result = $apiInstance->getById($id);
  177. $apiInstance->setDisabledTenancy(false);
  178. if ($result) {
  179. $content = $result->__toString();
  180. $content = (new CurlOptions())->clearNull($content);
  181. $codeResponse = 200;
  182. } else {
  183. $content = "No se encontro el id = " . $id;
  184. }
  185. } catch (Throwable $e) {
  186. $content = $e->getCode() . " - " . $e->getMessage();
  187. }
  188. } catch (Throwable $t) {
  189. $content = $t->getCode() . " - " . $t->getMessage();
  190. }
  191. return Utils::returnJSON($content, $codeResponse);
  192. });
  193. }
  194. public function getProfiles(Application $app)
  195. {
  196. $app->get('/api/v1/cablemodem/profiles', function (Application $app, Request $request) {
  197. $ch = new Checks();
  198. $codeResponse = 400;
  199. try {
  200. $config = $this->setUserPasswordConfig($request, Configuration::getDefaultConfiguration());
  201. $apiInstance = new ProfileApi(
  202. new Client(),
  203. $config
  204. );
  205. try {
  206. $page = $ch->integer($request, "page", false);
  207. $limit = $ch->integer($request, "limit", false);
  208. $id = $ch->integer($request, "id", false);
  209. $name = $ch->string($request, "name", false);
  210. $downstream = $ch->integer($request, "downstream", false);
  211. $upstream = $ch->integer($request, "upstream", false);
  212. $upload = $ch->integer($request, "upload", false);
  213. $download = $ch->integer($request, "download", false);
  214. $maxcpe = $ch->integer($request, "maxcpe", false);
  215. $tenancyId = $ch->integer($request, "tenancyId", false);
  216. $qb_criteria = $ch->integer($request, "qb-criteria", false, null);
  217. $content = "[";
  218. $result = $apiInstance->getList($id, $name, $downstream, $upstream, $upload, $download, $maxcpe, $tenancyId, $qb_criteria, $limit, $page);
  219. foreach ($result as $v) {
  220. // se eliminan los null
  221. $content .= $v->__toString() . ",";
  222. }
  223. if (strlen($content) > 1) {
  224. $content = substr($content, 0, strlen($content) - 1);
  225. }
  226. $content .= "]";
  227. $content = (new CurlOptions())->clearNull($content);
  228. $codeResponse = 200;
  229. } catch (Throwable $e) {
  230. $content = $e->getCode() . " - " . $e->getMessage();
  231. }
  232. } catch (Throwable $t) {
  233. $content = $t->getCode() . " - " . $t->getMessage();
  234. }
  235. return Utils::returnJSON($content, $codeResponse);
  236. });
  237. }
  238. public function getCablemodemId(Application $app)
  239. {
  240. $app->get('/api/v1/cablemodem/cablemodem', function (Application $app, Request $request) {
  241. $ch = new Checks();
  242. $codeResponse = 400;
  243. try {
  244. $config = $this->setUserPasswordConfig($request, Configuration::getDefaultConfiguration());
  245. $apiInstance = new CablemodemApi(
  246. new Client(),
  247. $config
  248. );
  249. try {
  250. $id = $ch->integer($request, "id");
  251. $apiInstance->setDisabledTenancy(true);
  252. $result = $apiInstance->getById($id);
  253. $apiInstance->setDisabledTenancy(false);
  254. if ($result) {
  255. $content = $result->__toString();
  256. $content = (new CurlOptions())->clearNull($content);
  257. $codeResponse = 200;
  258. } else {
  259. $content = "No se encontro el id = " . $id;
  260. }
  261. } catch (Throwable $e) {
  262. $content = $e->getCode() . " - " . $e->getMessage();
  263. }
  264. } catch (Throwable $t) {
  265. $content = $t->getCode() . " - " . $t->getMessage();
  266. }
  267. return Utils::returnJSON($content, $codeResponse);
  268. });
  269. }
  270. public function getCablemodems(Application $app)
  271. {
  272. $app->get('/api/v1/cablemodem/cablemodems', function (Application $app, Request $request) {
  273. $ch = new Checks();
  274. $codeResponse = 400;
  275. try {
  276. $config = $this->setUserPasswordConfig($request, Configuration::getDefaultConfiguration());
  277. $apiInstance = new CablemodemApi(
  278. new Client(),
  279. $config
  280. );
  281. try {
  282. $page = $ch->integer($request, "page", false);
  283. $limit = $ch->integer($request, "limit", false);
  284. $id = $ch->integer($request, "id", false);
  285. $clientId = $ch->string($request, "clientId", false);
  286. $mac = $ch->integer($request, "mac", false);
  287. $node = $ch->string($request, "node", false);
  288. $profile = $ch->string($request, "profiel", false);
  289. $model = $ch->string($request, "model", false);
  290. $tenancyId = $ch->integer($request, "tenancyId", false);
  291. $qb_criteria = $ch->integer($request, "qb-criteria", false, null);
  292. $content = "[";
  293. $result = $apiInstance->getList($id, $clientId, $mac, $node, $profile, $model, $tenancyId, $qb_criteria, $limit, $page);
  294. foreach ($result as $v) {
  295. // se eliminan los null
  296. $content .= $v->__toString() . ",";
  297. }
  298. if (strlen($content) > 1) {
  299. $content = substr($content, 0, strlen($content) - 1);
  300. }
  301. $content .= "]";
  302. $content = (new CurlOptions())->clearNull($content);
  303. $codeResponse = 200;
  304. } catch (Throwable $e) {
  305. $content = $e->getCode() . " - " . $e->getMessage();
  306. }
  307. } catch (Throwable $t) {
  308. $content = $t->getCode() . " - " . $t->getMessage();
  309. }
  310. return Utils::returnJSON($content, $codeResponse);
  311. });
  312. }
  313. public function postCablemodem(Application $app)
  314. {
  315. $app->post('/api/v1/cablemodem/cablemodem', function (Application $app, Request $request) {
  316. $codeResponse = 400;
  317. try {
  318. $config = $this->setUserPasswordConfig($request, Configuration::getDefaultConfiguration());
  319. $configBase = $this->setUserPasswordConfig($request, ConfigurationBase::getDefaultConfiguration());
  320. $apiInstance = new CablemodemApi(
  321. new Client(),
  322. $config
  323. );
  324. $data = json_decode(file_get_contents('php://input'), true);
  325. $utils = new Utils();
  326. $instance = $utils->loadData(new CablemodemCRUD(), $data);
  327. $errors = $instance->listInvalidProperties();
  328. if (is_null($instance->getMac()) || trim($instance->getMac()) == "") {
  329. $content = "Debe cargar la mac del cablemodem.";
  330. } elseif (preg_match('/([a-fA-F0-9]{2}[:|\-]?){6}/', trim($instance->getMac())) == 0) {
  331. $content = "La mac es incorrecta.";
  332. } elseif (is_null($instance->getProfile()) ||
  333. !is_numeric($instance->getProfile()) ||
  334. $instance->getProfile() <= 0) {
  335. $content = "Debe cargar el perfil del cablemodem.";
  336. } elseif (count($errors) === 0) {
  337. // chequeo la tenencia
  338. $apiValidationBase = new ValidationApiBase(
  339. new Client(),
  340. $configBase
  341. );
  342. $apiValidationCablemodem = new ValidationApi(
  343. new Client(),
  344. $config
  345. );
  346. $content = null;
  347. // verifico si existe la tenencia
  348. if ($apiValidationBase->validTenancy($instance->getTenancyId())) {
  349. if (!is_null($instance->getClientId()) && $instance->getClientId() > 0) {
  350. // chequeo el cliente exista
  351. if (!$apiValidationBase->validClient($instance->getClientId())) {
  352. $content = "El id del cliente no existe.";
  353. }
  354. }
  355. if (is_null($content)) {
  356. // mostrar error de que la mac ya existe
  357. $result = $apiValidationCablemodem->existsCablemodem($instance->getMac(), $instance->getTenancyId());
  358. $name = "";
  359. if ($result) {
  360. $name = $result->getId() . " - " . $result->getMac();
  361. }
  362. if ($name == "") {
  363. if (!is_null($instance->getNode())) {
  364. if (!$apiValidationCablemodem->validNode($instance->getNode())) {
  365. $content = "El id de nodo no existe.";
  366. }
  367. }
  368. if (is_null($content)) {
  369. if (!is_null($instance->getProfile())) {
  370. if (!$apiValidationCablemodem->validProfile($instance->getProfile())) {
  371. $content = "El id del profile no existe.";
  372. }
  373. }
  374. if (is_null($content)) {
  375. if (!is_null($instance->getModel())) {
  376. if (!$apiValidationCablemodem->validCablemodemModel($instance->getModel())) {
  377. $content = "El id del modelo no existe.";
  378. }
  379. }
  380. if (is_null($content)) {
  381. $apiInstance->create($instance);
  382. // busco el id del cliente, buscandolo por mac
  383. $result = $apiValidationCablemodem->existsCablemodem($instance->getMac(), $instance->getTenancyId());
  384. if ($result) {
  385. $content = $result->__toString();
  386. $codeResponse = 200;
  387. } else {
  388. $content = "No se pudo obtener el cablemodem cargado. Verifique por sistema si la carga se realizo correctamente.";
  389. }
  390. }
  391. }
  392. }
  393. } else {
  394. $codeResponse = 409;
  395. $content = "La MAC ya existe y pertenece al cablemodem " . $name . ".";
  396. }
  397. }
  398. } else {
  399. $content = "El id de tenencia es incorrecto.";
  400. }
  401. } else {
  402. $content = json_encode($errors);
  403. }
  404. } catch (Throwable $t) {
  405. $content = $t->getCode() . " - " . $t->getMessage();
  406. }
  407. return Utils::returnJSON($content, $codeResponse);
  408. });
  409. }
  410. public function putCablemodem(Application $app)
  411. {
  412. $app->put('/api/v1/cablemodem/cablemodem', function (Application $app, Request $request) {
  413. $codeResponse = 400;
  414. try {
  415. $config = $this->setUserPasswordConfig($request, Configuration::getDefaultConfiguration());
  416. $configBase = $this->setUserPasswordConfig($request, ConfigurationBase::getDefaultConfiguration());
  417. $apiInstance = new CablemodemApi(
  418. new Client(),
  419. $config
  420. );
  421. $data = json_decode(file_get_contents('php://input'), true);
  422. $utils = new Utils();
  423. $instance = $utils->loadData(new CablemodemCRUD(), $data);
  424. $errors = $instance->listInvalidProperties();
  425. if (is_null($instance->getMac()) || trim($instance->getMac()) == "") {
  426. $content = "Debe cargar la mac del cablemodem.";
  427. } elseif (is_null($instance->getProfile()) ||
  428. !is_numeric($instance->getProfile()) ||
  429. $instance->getProfile() <= 0) {
  430. $content = "Debe cargar el perfil del cablemodem.";
  431. } elseif (count($errors) === 0) {
  432. // chequeo la tenencia
  433. $apiValidationBase = new ValidationApiBase(
  434. new Client(),
  435. $configBase
  436. );
  437. $apiValidationCablemodem = new ValidationApi(
  438. new Client(),
  439. $config
  440. );
  441. $content = null;
  442. // verifico si existe la tenencia
  443. if ($apiValidationBase->validTenancy($instance->getTenancyId())) {
  444. if (!is_null($instance->getClientId()) && $instance->getClientId() > 0) {
  445. // chequeo el cliente exista
  446. if (!$apiValidationBase->validClient($instance->getClientId())) {
  447. $content = "El id del cliente no existe.";
  448. }
  449. }
  450. if (is_null($content)) {
  451. // mostrar error de que la mac ya existe
  452. $result = $apiValidationCablemodem->existsCablemodem($instance->getMac(), $instance->getTenancyId());
  453. $name = "";
  454. if ($result && $result->getId() != $instance->getId()) {
  455. $name = $result->getId() . " - " . $result->getMac();
  456. }
  457. if ($name == "") {
  458. if (!is_null($instance->getNode())) {
  459. if (!$apiValidationCablemodem->validNode($instance->getNode())) {
  460. $content = "El id de nodo no existe.";
  461. }
  462. }
  463. if (is_null($content)) {
  464. if (!is_null($instance->getProfile())) {
  465. if (!$apiValidationCablemodem->validProfile($instance->getProfile())) {
  466. $content = "El id del profile no existe.";
  467. }
  468. }
  469. if (is_null($content)) {
  470. if (!is_null($instance->getModel())) {
  471. if (!$apiValidationCablemodem->validCablemodemModel($instance->getModel())) {
  472. $content = "El id del modelo no existe.";
  473. }
  474. }
  475. if (is_null($content)) {
  476. $apiInstance->update($instance->getId(), $instance);
  477. // busco el id del cliente, buscandolo por externalid
  478. $apiInstance->setDisabledTenancy(true);
  479. $result = $apiInstance->getById($instance->getId());
  480. $apiInstance->setDisabledTenancy(false);
  481. if ($result) {
  482. $content = $result->__toString();
  483. $codeResponse = 200;
  484. } else {
  485. $content = "No se pudo obtener el cablemodem cargado. Verifique por sistema si la carga se realizo correctamente.";
  486. }
  487. }
  488. }
  489. }
  490. } else {
  491. $codeResponse = 409;
  492. $content = "La MAC ya existe y pertenece al cablemodem " . $name . ".";
  493. }
  494. }
  495. } else {
  496. $content = "El id de tenencia es incorrecto.";
  497. }
  498. } else {
  499. $content = json_encode($errors);
  500. }
  501. } catch (Throwable $t) {
  502. $content = $t->getCode() . " - " . $t->getMessage();
  503. }
  504. return Utils::returnJSON($content, $codeResponse);
  505. });
  506. }
  507. public function deleteCablemodem(Application $app)
  508. {
  509. $app->delete('/api/v1/cablemodem/cablemodem', function (Application $app, Request $request) {
  510. $codeResponse = 400;
  511. try {
  512. $config = $this->setUserPasswordConfig($request, Configuration::getDefaultConfiguration());
  513. $apiInstance = new CablemodemApi(
  514. new Client(),
  515. $config
  516. );
  517. $ch = new Checks();
  518. $id = $ch->integer($request, "id", true);
  519. $apiInstance->setDisabledTenancy(true);
  520. $result = $apiInstance->getById($id);
  521. $apiInstance->setDisabledTenancy(false);
  522. if (!is_null($result)) {
  523. $apiInstance->delete($id);
  524. $content = $result->__toString();
  525. $codeResponse = 200;
  526. } else {
  527. $content = "No se encontro el id = " . $id;
  528. }
  529. } catch (Throwable $t) {
  530. $content = $t->getCode() . " - " . $t->getMessage();
  531. }
  532. return Utils::returnJSON($content, $codeResponse);
  533. });
  534. }
  535. public function getCablemodemActive(Application $app)
  536. {
  537. $app->get('/api/v1/cablemodem/cablemodem/active', function (Application $app, Request $request) {
  538. $codeResponse = 400;
  539. try {
  540. $config = $this->setUserPasswordConfig($request, Configuration::getDefaultConfiguration());
  541. $apiInstance = new CablemodemApi(
  542. new Client(),
  543. $config
  544. );
  545. $ch = new Checks();
  546. $id = $ch->integer($request, "id", true);
  547. $workflow = "administrative_state";
  548. $transition = "suspend_to_active";
  549. $apiInstance->setDisabledTenancy(true);
  550. $result = $apiInstance->getById($id);
  551. $apiInstance->setDisabledTenancy(false);
  552. if (!is_null($result)) {
  553. $apiInstance->apply($id, $workflow, $transition);
  554. $apiInstance->setDisabledTenancy(true);
  555. $result = $apiInstance->getById($id);
  556. $apiInstance->setDisabledTenancy(false);
  557. if ($result) {
  558. $content = $result->__toString();
  559. $codeResponse = 200;
  560. } else {
  561. $content = "No se pudo obtener el acceso cargado. Verifique por sistema si la carga se realizo correctamente.";
  562. }
  563. } else {
  564. $content = "No se encontro el cablemodem de id = " . $id;
  565. }
  566. } catch (Throwable $t) {
  567. $content = $t->getCode() . " - " . $t->getMessage();
  568. }
  569. return Utils::returnJSON($content, $codeResponse);
  570. });
  571. }
  572. public function getCablemodemDisable(Application $app)
  573. {
  574. $app->get('/api/v1/cablemodem/cablemodem/disable', function (Application $app, Request $request) {
  575. $codeResponse = 400;
  576. try {
  577. $config = $this->setUserPasswordConfig($request, Configuration::getDefaultConfiguration());
  578. $apiInstance = new CablemodemApi(
  579. new Client(),
  580. $config
  581. );
  582. $ch = new Checks();
  583. $id = $ch->integer($request, "id", true);
  584. $workflow = "administrative_state";
  585. $transition = "active_to_suspend";
  586. $apiInstance->setDisabledTenancy(true);
  587. $result = $apiInstance->getById($id);
  588. $apiInstance->setDisabledTenancy(false);
  589. if (!is_null($result)) {
  590. $apiInstance->apply($id, $workflow, $transition);
  591. $apiInstance->setDisabledTenancy(true);
  592. $result = $apiInstance->getById($id);
  593. $apiInstance->setDisabledTenancy(false);
  594. if ($result) {
  595. $content = $result->__toString();
  596. $codeResponse = 200;
  597. } else {
  598. $content = "No se pudo obtener el acceso cargado. Verifique por sistema si la carga se realizo correctamente.";
  599. }
  600. } else {
  601. $content = "No se encontro el cablemodem de id = " . $id;
  602. }
  603. } catch (Throwable $t) {
  604. $content = $t->getCode() . " - " . $t->getMessage();
  605. }
  606. return Utils::returnJSON($content, $codeResponse);
  607. });
  608. }
  609. public function getCablemodemSupply(Application $app)
  610. {
  611. $app->get('/api/v1/cablemodem/cablemodem/supply', function (Application $app, Request $request) {
  612. $codeResponse = 400;
  613. try {
  614. $config = $this->setUserPasswordConfig($request, Configuration::getDefaultConfiguration());
  615. $apiInstance = new CablemodemApi(
  616. new Client(),
  617. $config
  618. );
  619. $ch = new Checks();
  620. $mac = $ch->string($request, "mac", true);
  621. $activationCode = $ch->string($request, "activationCode", true);
  622. $apiInstance->setDisabledTenancy(true);
  623. $result = $apiInstance->getList(null, null, $mac);
  624. $apiInstance->setDisabledTenancy(false);
  625. $util = new \Utils();
  626. $result = $util->valueExistsLower($mac,
  627. $result,
  628. "getMac");
  629. if (!is_null($result)) {
  630. $instance = new CablemodemCRUD();
  631. $instance->setId($result->getId());
  632. $instance->setActivationCode($activationCode);
  633. $apiInstance->update($result->getId(), $instance);
  634. $apiInstance->setDisabledTenancy(true);
  635. $result = $apiInstance->getById($result->getId());
  636. $apiInstance->setDisabledTenancy(false);
  637. if ($result) {
  638. $content = $result->__toString();
  639. $codeResponse = 200;
  640. } else {
  641. $content = "No se pudo obtener el acceso cargado. Verifique por sistema si la carga se realizo correctamente.";
  642. }
  643. } else {
  644. $content = "No se encontro el cablemodem de mac = " . $mac;
  645. }
  646. } catch (Throwable $t) {
  647. $content = $t->getCode() . " - " . $t->getMessage();
  648. }
  649. return Utils::returnJSON($content, $codeResponse);
  650. });
  651. }
  652. }