OLT.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  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 JMS\Serializer\Annotation as JMS;
  8. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  9. use Symfony\Component\Validator\Constraints as Assert;
  10. use Symfony\Component\Workflow\Exception\ExceptionInterface;
  11. use DeviceBundle\Validator\Constraints as ValidatorAssert;
  12. use DeviceBundle\Interfaces\DeviceInterface;
  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. use Base\AdminBundle\Interfaces\SoftDeleteInterface;
  20. /**
  21. * @ORM\Entity
  22. * @UniqueEntity("ip")
  23. * @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=true)
  24. *
  25. * @ValidatorAssert\Device
  26. */
  27. class OLT implements DeviceInterface, TenancyIdTraitInterface, LocationInterface, WorkflowInterface, SoftDeleteInterface
  28. {
  29. use ExtraDataTrait;
  30. use TenancyIdTrait;
  31. use LocationTrait;
  32. use WorkflowTrait;
  33. use SoftDeleteable;
  34. /**
  35. * @var bigint $id
  36. *
  37. * @ORM\Column(type="bigint", nullable=false)
  38. * @ORM\Id
  39. * @ORM\GeneratedValue(strategy="IDENTITY")
  40. */
  41. private $id;
  42. /**
  43. * @var string $name
  44. *
  45. * @ORM\Column(type="string", length=255)
  46. * @Assert\NotNull
  47. */
  48. protected $name;
  49. /**
  50. * @var string $ip
  51. *
  52. * @ORM\Column(type="string", length=50, nullable=true, unique=true)
  53. */
  54. protected $ip;
  55. /**
  56. * @var string $snmpCommunity
  57. *
  58. * @ORM\Column(type="string", length=255, nullable=true, unique=false)
  59. */
  60. protected $snmpCommunity;
  61. /**
  62. * @var string $sshUser
  63. *
  64. * @ORM\Column(type="string", length=255, nullable=true, unique=false)
  65. */
  66. protected $sshUser;
  67. /**
  68. * @var string $sshPass
  69. *
  70. * @ORM\Column(type="string", length=255, nullable=true, unique=false)
  71. */
  72. protected $sshPass;
  73. /**
  74. * @var string $libraryVersion
  75. *
  76. * @ORM\Column(type="string", length=255, nullable=true, unique=false)
  77. */
  78. protected $libraryVersion;
  79. /**
  80. * @ORM\ManyToOne(targetEntity="OLTModel", inversedBy="olts", fetch="EXTRA_LAZY")
  81. * @ORM\JoinColumn(name="model_id", referencedColumnName="id", onDelete="SET NULL")
  82. *
  83. * @JMS\MaxDepth(1)
  84. */
  85. protected $model;
  86. /**
  87. * @ORM\OneToMany(targetEntity="ONU", mappedBy="olt", fetch="EXTRA_LAZY")
  88. *
  89. * @JMS\MaxDepth(2)
  90. */
  91. protected $onus;
  92. /**
  93. * @ORM\Column(type="string", nullable=true)
  94. */
  95. protected $currentState = null;
  96. /**
  97. * @ORM\Column(type="string", nullable=false, options={"default": "success"})
  98. */
  99. protected $transitionState = 'success';
  100. /**
  101. * @ORM\ManyToOne(targetEntity="\WorkflowBundle\Entity\Workflow", fetch="EXTRA_LAZY")
  102. * @ORM\JoinColumn(name="workflow_id", referencedColumnName="id", onDelete="SET NULL")
  103. *
  104. * @JMS\MaxDepth(1)
  105. */
  106. protected $workflow;
  107. /**
  108. * @ORM\Column(type="boolean", nullable=true, columnDefinition="BOOLEAN DEFAULT TRUE")
  109. */
  110. protected $executeSnmp = true;
  111. /**
  112. * @ORM\Column(type="integer", options={"unsigned":true, "default":10})
  113. */
  114. protected $timeScan = 10;
  115. /**
  116. * @ORM\Column(type="integer", options={"unsigned":true, "default":5})
  117. */
  118. protected $timeOltOctets = 5;
  119. /**
  120. * @ORM\Column(type="integer", options={"unsigned":true, "default":5})
  121. */
  122. protected $timePonStats = 5;
  123. /**
  124. * @ORM\Column(type="integer", options={"unsigned":true, "default":5})
  125. */
  126. protected $timeOnuStats = 5;
  127. /**
  128. * @ORM\Column(type="string", nullable=true)
  129. */
  130. protected $enable;
  131. /**
  132. * @return string
  133. */
  134. public function __toString()
  135. {
  136. return (string) $this->name;
  137. }
  138. /**
  139. * @return int
  140. */
  141. public function getId()
  142. {
  143. return $this->id;
  144. }
  145. /**
  146. * @return string
  147. */
  148. public function getName()
  149. {
  150. return $this->name;
  151. }
  152. /**
  153. * @return string
  154. */
  155. public function getIp()
  156. {
  157. return $this->ip;
  158. }
  159. /**
  160. * @return string
  161. */
  162. public function getSnmpCommunity()
  163. {
  164. return $this->snmpCommunity;
  165. }
  166. /**
  167. * @return string
  168. */
  169. public function getSshUser()
  170. {
  171. return $this->sshUser;
  172. }
  173. /**
  174. * @return string
  175. */
  176. public function getSshPass()
  177. {
  178. return $this->sshPass;
  179. }
  180. /**
  181. * @param string $name
  182. * @return $this
  183. */
  184. public function setName($name)
  185. {
  186. $this->name = $name;
  187. return $this;
  188. }
  189. /**
  190. * @param string $ip
  191. * @return $this
  192. */
  193. public function setIp($ip)
  194. {
  195. $this->ip = $ip;
  196. return $this;
  197. }
  198. /**
  199. * @param string $snmpCommunity
  200. * @return $this
  201. */
  202. public function setSnmpCommunity($snmpCommunity)
  203. {
  204. $this->snmpCommunity = $snmpCommunity;
  205. return $this;
  206. }
  207. /**
  208. * @param string $sshUser
  209. * @return $this
  210. */
  211. public function setSshUser($sshUser)
  212. {
  213. $this->sshUser = $sshUser;
  214. return $this;
  215. }
  216. /**
  217. * @param string $sshPass
  218. * @return $this
  219. */
  220. public function setSshPass($sshPass)
  221. {
  222. $this->sshPass = $sshPass;
  223. return $this;
  224. }
  225. /**
  226. * @param ONU $onu
  227. * @return OLT
  228. */
  229. public function addOnu(ONU $onu)
  230. {
  231. $this->onus[] = $onu;
  232. return $this;
  233. }
  234. /**
  235. * @param ONU $onu
  236. * @return OLT
  237. */
  238. public function removeOnu(ONU $onu)
  239. {
  240. $this->onus->removeElement($onu);
  241. return $this;
  242. }
  243. /**
  244. * @return Doctrine\Common\Collections\Collection
  245. */
  246. public function getOnus()
  247. {
  248. return $this->onus;
  249. }
  250. /**
  251. * @return OLTModel
  252. */
  253. public function getModel()
  254. {
  255. return $this->model;
  256. }
  257. /**
  258. * @param OLTModel $model
  259. * @return $this
  260. */
  261. public function setModel($model)
  262. {
  263. $this->model = $model;
  264. return $this;
  265. }
  266. /* Va a quedar deprecate */
  267. public function getWorkflowObject()
  268. {
  269. if ($this->model) {
  270. $model = $this->model;
  271. if ($model->getWorkflow()) {
  272. return $model->getWorkflow();
  273. }
  274. }
  275. return $this->workflow;
  276. }
  277. /**
  278. * @return array
  279. */
  280. public function getDeviceData()
  281. {
  282. $deviceData = array();
  283. $deviceData['deviceType'] = get_class($this);
  284. $deviceData['deviceId'] = $this->id;
  285. $deviceData['ip'] = $this->ip;
  286. $deviceData['tenancy'] = $this->tenancyId;
  287. $deviceExtraData = array('snmpCommunity' => $this->snmpCommunity, 'sshUser' => $this->sshUser, 'sshPass' => $this->sshPass,
  288. 'libraryVersion' => $this->libraryVersion, 'name' => $this->name);
  289. if ($this->model) {
  290. $model = $this->getModel();
  291. $deviceExtraData['modelId'] = $model->getId();
  292. $deviceExtraData['mark'] = $model->getMark();
  293. $deviceExtraData['library'] = $model->getLibrary();
  294. } else {
  295. $deviceExtraData['modelId'] = null;
  296. $deviceExtraData['mark'] = null;
  297. $deviceExtraData['library'] = null;
  298. }
  299. $deviceExtraData['executeSnmp'] = $this->executeSnmp;
  300. $deviceExtraData['timeScan'] = $this->timeScan;
  301. $deviceExtraData['timeOnuStats'] = $this->timeOnuStats;
  302. $deviceExtraData['timePonStats'] = $this->timePonStats;
  303. $deviceExtraData['timeOltOctets'] = $this->timeOltOctets;
  304. $deviceData['extraData'] = json_encode($deviceExtraData);
  305. return $deviceData;
  306. }
  307. /**
  308. * Set executeSnmp
  309. *
  310. * @param boolean $e
  311. * @return OLT
  312. */
  313. public function setExecuteSnmp($e)
  314. {
  315. $this->executeSnmp = $e;
  316. return $this;
  317. }
  318. /**
  319. * Get executeSnmp
  320. *
  321. * @return boolean
  322. */
  323. public function getExecuteSnmp()
  324. {
  325. return $this->executeSnmp;
  326. }
  327. /**
  328. * Set timeScan
  329. *
  330. * @param integer $timeScan
  331. */
  332. public function setTimeScan($timeScan)
  333. {
  334. $this->timeScan = $timeScan;
  335. }
  336. /**
  337. * Get timeScan
  338. *
  339. * @return integer
  340. */
  341. public function getTimeScan()
  342. {
  343. return $this->timeScan;
  344. }
  345. /**
  346. * Set timeOltOctets
  347. *
  348. * @param integer $timeOltOctets
  349. */
  350. public function setTimeOltOctets($timeOltOctets)
  351. {
  352. $this->timeOltOctets = $timeOltOctets;
  353. }
  354. /**
  355. * Get timeOltOctets
  356. *
  357. * @return integer
  358. */
  359. public function getTimeOltOctets()
  360. {
  361. return $this->timeOltOctets;
  362. }
  363. /**
  364. * Set timeOnuStats
  365. *
  366. * @param integer $timeOnuStats
  367. */
  368. public function setTimeOnuStats($timeOnuStats)
  369. {
  370. $this->timeOnuStats = $timeOnuStats;
  371. }
  372. /**
  373. * Get timeOnuStats
  374. *
  375. * @return integer
  376. */
  377. public function getTimeOnuStats()
  378. {
  379. return $this->timeOnuStats;
  380. }
  381. /**
  382. * Set timePonStats
  383. *
  384. * @param integer $timePonStats
  385. */
  386. public function setTimePonStats($timePonStats)
  387. {
  388. $this->timePonStats = $timePonStats;
  389. }
  390. /**
  391. * Get timePonStats
  392. *
  393. * @return integer
  394. */
  395. public function getTimePonStats()
  396. {
  397. return $this->timePonStats;
  398. }
  399. /**
  400. * @return string
  401. */
  402. public function getEnable()
  403. {
  404. return $this->enable;
  405. }
  406. /**
  407. * @param string $enable
  408. *
  409. * @return $this
  410. */
  411. public function setEnable($enable)
  412. {
  413. $this->enable = $enable;
  414. return $this;
  415. }
  416. /**
  417. * @return int
  418. */
  419. public function getLibraryVersion()
  420. {
  421. return $this->libraryVersion;
  422. }
  423. /**
  424. * @return array
  425. */
  426. public function getSoftDeleteCriteria()
  427. {
  428. return array('ip' => $this->ip);
  429. }
  430. }