ONU.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563
  1. <?php
  2. namespace FTTHBundle\Entity;
  3. use Base\AdminBundle\Traits\TenancyIdTrait;
  4. use Base\AdminBundle\Traits\TenancyIdTraitInterface;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use ExtraDataBundle\Entity\Traits\ExtraDataTrait;
  7. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  8. use Symfony\Component\Validator\Constraints as Assert;
  9. use Symfony\Component\Workflow\Exception\ExceptionInterface;
  10. use DeviceBundle\Validator\Constraints as ValidatorAssert;
  11. use DeviceBundle\Interfaces\DeviceInterface;
  12. use JMS\Serializer\Annotation as JMS;
  13. use MapBundle\Entity\Interfaces\LocationInterface;
  14. use MapBundle\Entity\Traits\LocationTrait;
  15. use WorkflowBundle\Entity\Interfaces\WorkflowInterface;
  16. use WorkflowBundle\Entity\Traits\WorkflowTrait;
  17. use Gedmo\SoftDeleteable\Traits\SoftDeleteableEntity as SoftDeleteable;
  18. use Gedmo\Mapping\Annotation as Gedmo;
  19. /**
  20. * ONU
  21. *
  22. * @ORM\Entity(repositoryClass="FTTHBundle\Repository\ONURepository")
  23. * @UniqueEntity(fields={"ponSerialNumber", "tenancyId"}, message="errors.duplicate_key")
  24. * @ORM\Table(uniqueConstraints={@ORM\UniqueConstraint(name="unique_idx", columns={"pon_serial_number", "tenancy_id"})})
  25. * @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=true)
  26. *
  27. * @ValidatorAssert\Device
  28. */
  29. class ONU implements DeviceInterface, TenancyIdTraitInterface, LocationInterface, WorkflowInterface
  30. {
  31. use ExtraDataTrait;
  32. use TenancyIdTrait;
  33. use LocationTrait;
  34. use WorkflowTrait;
  35. use SoftDeleteable;
  36. /**
  37. * @var int
  38. *
  39. * @ORM\Column(name="id", type="integer", nullable=false)
  40. * @ORM\Id
  41. * @ORM\GeneratedValue(strategy="AUTO")
  42. */
  43. private $id;
  44. /**
  45. * @var string
  46. *
  47. * @ORM\Column(type="string", length=15, nullable=true)
  48. * @Assert\Ip
  49. */
  50. private $ip;
  51. /**
  52. * @var string
  53. *
  54. * @ORM\Column(type="string", length=12, nullable=true)
  55. */
  56. private $mac;
  57. /**
  58. * @var string
  59. *
  60. * @ORM\Column(type="string", length=11, nullable=true)
  61. */
  62. private $serialNumber;
  63. /**
  64. * @var string
  65. *
  66. * @ORM\Column(type="string", length=16, nullable=false, unique=true)
  67. */
  68. private $ponSerialNumber;
  69. /**
  70. * @var int
  71. *
  72. * @ORM\Column(type="integer", nullable=false)
  73. * @Assert\NotNull
  74. */
  75. private $clientId;
  76. /**
  77. * @Gedmo\Timestampable(on="create")
  78. * @ORM\Column(type="datetime")
  79. */
  80. protected $created;
  81. /**
  82. * @Gedmo\Timestampable(on="update")
  83. * @ORM\Column(type="datetime")
  84. */
  85. protected $updated;
  86. /**
  87. * @ORM\Column(type="string", nullable=true)
  88. */
  89. protected $currentState = null;
  90. /**
  91. * @ORM\Column(type="string", nullable=true, options={"default": "active"})
  92. */
  93. protected $administrativeState = 'active';
  94. /**
  95. * @ORM\Column(type="string", nullable=false, options={"default": "success"})
  96. */
  97. protected $transitionState = 'success';
  98. /**
  99. * @ORM\ManyToOne(targetEntity="OLT", inversedBy="onus", fetch="EXTRA_LAZY")
  100. * @JMS\MaxDepth(1)
  101. */
  102. protected $olt;
  103. /**
  104. * @ORM\ManyToOne(targetEntity="ONUModel", inversedBy="onus", fetch="EXTRA_LAZY")
  105. * @ORM\JoinColumn(name="model_id", referencedColumnName="id", onDelete="SET NULL")
  106. * @JMS\MaxDepth(1)
  107. */
  108. protected $model;
  109. /**
  110. * @ORM\ManyToOne(targetEntity="NAP", inversedBy="onus", fetch="EXTRA_LAZY")
  111. *
  112. * @JMS\MaxDepth(1)
  113. */
  114. protected $nap;
  115. /**
  116. * @ORM\ManyToOne(targetEntity="Profile", inversedBy="onus", fetch="EXTRA_LAZY")
  117. * @JMS\MaxDepth(1)
  118. */
  119. protected $profile;
  120. /**
  121. * @ORM\ManyToOne(targetEntity="\WorkflowBundle\Entity\Workflow", fetch="EXTRA_LAZY")
  122. * @ORM\JoinColumn(name="workflow_id", referencedColumnName="id", onDelete="SET NULL")
  123. * @JMS\MaxDepth(1)
  124. */
  125. protected $workflow;
  126. /**
  127. * @var int
  128. *
  129. * @ORM\Column(type="integer", nullable=false, options={"default": "0"})
  130. */
  131. private $position = 0;
  132. /**
  133. * @return string
  134. */
  135. public function __toString()
  136. {
  137. return (string) $this->ponSerialNumber;
  138. }
  139. /**
  140. * Get id
  141. *
  142. * @return int
  143. */
  144. public function getId()
  145. {
  146. return $this->id;
  147. }
  148. /**
  149. * Get id
  150. *
  151. * @param int
  152. *
  153. * @return ONU
  154. */
  155. public function setId($id)
  156. {
  157. $this->id = $id;
  158. return $this;
  159. }
  160. /**
  161. * Set ip
  162. *
  163. * @param string $ip
  164. *
  165. * @return ONU
  166. */
  167. public function setIp($ip)
  168. {
  169. $this->ip = $ip;
  170. return $this;
  171. }
  172. /**
  173. * Get ip
  174. *
  175. * @return string
  176. */
  177. public function getIp()
  178. {
  179. return $this->ip;
  180. }
  181. /**
  182. * Set mac
  183. *
  184. * @param string $mac
  185. *
  186. * @return ONU
  187. */
  188. public function setMac($mac)
  189. {
  190. $this->mac = $mac;
  191. return $this;
  192. }
  193. /**
  194. * Get mac
  195. *
  196. * @return string
  197. */
  198. public function getMac()
  199. {
  200. return $this->mac;
  201. }
  202. /**
  203. * Set serialNumber
  204. *
  205. * @param string $serialNumber
  206. *
  207. * @return ONU
  208. */
  209. public function setSerialNumber($serialNumber)
  210. {
  211. $this->serialNumber = $serialNumber;
  212. return $this;
  213. }
  214. /**
  215. * Get serialNumber
  216. *
  217. * @return string
  218. */
  219. public function getSerialNumber()
  220. {
  221. return $this->serialNumber;
  222. }
  223. /**
  224. * Set ponSerialNumber
  225. *
  226. * @param string $ponSerialNumber
  227. *
  228. * @return ONU
  229. */
  230. public function setPonSerialNumber($ponSerialNumber)
  231. {
  232. $this->ponSerialNumber = strtolower($ponSerialNumber);
  233. return $this;
  234. }
  235. /**
  236. * Get ponSerialNumber
  237. *
  238. * @return string
  239. */
  240. public function getPonSerialNumber()
  241. {
  242. return strtolower($this->ponSerialNumber);
  243. }
  244. /**
  245. * Set clientId
  246. *
  247. * @param integer $clientId
  248. *
  249. * @return ONU
  250. */
  251. public function setClientId($clientId)
  252. {
  253. $this->clientId = $clientId;
  254. return $this;
  255. }
  256. /**
  257. * Get clientId
  258. *
  259. * @return int
  260. */
  261. public function getClientId()
  262. {
  263. return $this->clientId;
  264. }
  265. /**
  266. * Get created
  267. *
  268. * @return \DateTime
  269. */
  270. public function getCreated()
  271. {
  272. return $this->created;
  273. }
  274. /**
  275. * Set created
  276. *
  277. * @param \DateTime
  278. *
  279. * @return ONU
  280. */
  281. public function setCreated($d)
  282. {
  283. $this->created = $d;
  284. return $this;
  285. }
  286. /**
  287. * Get updated
  288. *
  289. * @return \DateTime
  290. */
  291. public function getUpdated()
  292. {
  293. return $this->updated;
  294. }
  295. /**
  296. * Set updated
  297. *
  298. */
  299. public function setUpdated($updated)
  300. {
  301. $this->updated = $updated;
  302. return $this;
  303. }
  304. /**
  305. * Get administrativeState
  306. *
  307. */
  308. public function getAdministrativeState()
  309. {
  310. return $this->administrativeState;
  311. }
  312. /**
  313. * Set administrativeState
  314. *
  315. */
  316. public function setAdministrativeState($administrativeState)
  317. {
  318. $this->administrativeState = $administrativeState;
  319. return $this;
  320. }
  321. /**
  322. * @return OLT
  323. */
  324. public function getOlt()
  325. {
  326. return $this->olt;
  327. }
  328. /**
  329. * @param OLT $olt
  330. *
  331. * @return $this
  332. */
  333. public function setOlt($olt)
  334. {
  335. $this->olt = $olt;
  336. return $this;
  337. }
  338. /**
  339. * @return ONUModel
  340. */
  341. public function getModel()
  342. {
  343. return $this->model;
  344. }
  345. /**
  346. * @param ONUModel $model
  347. * @return $this
  348. */
  349. public function setModel($model)
  350. {
  351. $this->model = $model;
  352. return $this;
  353. }
  354. /**
  355. * @return NAP
  356. */
  357. public function getNap()
  358. {
  359. return $this->nap;
  360. }
  361. /**
  362. * @param NAP $nap
  363. *
  364. * @return $this
  365. */
  366. public function setNap($nap)
  367. {
  368. $this->nap = $nap;
  369. return $this;
  370. }
  371. /**
  372. * @return Profile
  373. */
  374. public function getProfile()
  375. {
  376. return $this->profile;
  377. }
  378. /**
  379. * @param Profile $profile
  380. * @return $this
  381. */
  382. public function setProfile($profile)
  383. {
  384. $this->profile = $profile;
  385. return $this;
  386. }
  387. /**
  388. * @global AppKernel $kernel
  389. *
  390. * @return string
  391. */
  392. public function getLog()
  393. {
  394. global $kernel;
  395. $env = $kernel->getEnvironment();
  396. $rootDir = $kernel->getRootDir();
  397. $log = $rootDir . "/../var/logs/" . $env . ".log";
  398. $out = array();
  399. exec("tail -400 {$log} | grep 'ONU_id_{$this->id}'", $out);
  400. return implode("\n", $out);
  401. }
  402. /* Va a quedar deprecate */
  403. public function getWorkflowObject()
  404. {
  405. return $this->workflow;
  406. }
  407. /**
  408. * @return string
  409. */
  410. public function getAdministrativeWorkflow()
  411. {
  412. return "administrative_state";
  413. }
  414. /**
  415. * Get getPosition
  416. *
  417. * @return int
  418. */
  419. public function getPosition()
  420. {
  421. return $this->position;
  422. }
  423. /**
  424. * Set getPosition
  425. *
  426. * No se recomienda usar este metodo, porque se debe calcular a partir del NAP
  427. *
  428. * @return $this
  429. */
  430. public function setPosition($position)
  431. {
  432. $this->position = $position;
  433. return $this;
  434. }
  435. /**
  436. * @return int
  437. */
  438. public function getSlot()
  439. {
  440. $olt = null;
  441. if ($this->nap) {
  442. $olt = $this->nap->getSlot();
  443. }
  444. return $olt;
  445. }
  446. /**
  447. * @return int
  448. */
  449. public function getLink()
  450. {
  451. $olt = null;
  452. if ($this->nap) {
  453. $olt = $this->nap->getLink();
  454. }
  455. return $olt;
  456. }
  457. /**
  458. * @return array
  459. */
  460. public function getDeviceData()
  461. {
  462. $deviceData = array();
  463. $deviceData['deviceType'] = get_class($this);
  464. $deviceData['deviceId'] = $this->id;
  465. $deviceData['ip'] = $this->ip;
  466. $deviceData['tenancy'] = $this->tenancyId;
  467. $deviceExtraData = array('mac' => $this->mac, 'serialNumber' => $this->serialNumber, 'ponSerialNumber' => $this->ponSerialNumber,
  468. 'clientId' => $this->clientId);
  469. ($this->olt) ? $olt = $this->getOlt()->getId() : $olt = null;
  470. ($this->model) ? $model = $this->getModel()->getId() : $model = null;
  471. ($this->nap) ? $nap = $this->getNap()->getId() : $nap = null;
  472. ($this->profile) ? $profile = $this->getProfile()->getId() : $profile = null;
  473. $deviceExtraData['oltId'] = $olt;
  474. $deviceExtraData['modelId'] = $model;
  475. $deviceExtraData['napId'] = $nap;
  476. $deviceExtraData['profileId'] = $profile;
  477. $deviceData['extraData'] = json_encode($deviceExtraData);
  478. return $deviceData;
  479. }
  480. }