|
@@ -2,12 +2,21 @@
|
|
|
|
|
|
namespace FTTHBundle\Controller;
|
|
|
|
|
|
-use FTTHBundle\Entity\NAP;
|
|
|
-use FTTHBundle\Entity\ONU;
|
|
|
+use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
|
|
-use FOS\RestBundle\Controller\Annotations\RouteResource;
|
|
|
-use Symfony\Component\HttpFoundation\JsonResponse;
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
+use Symfony\Component\HttpFoundation\JsonResponse;
|
|
|
+use Symfony\Component\HttpFoundation\Response;
|
|
|
+use MapBundle\Entity\Location;
|
|
|
+use FTTHBundle\Entity\ONU;
|
|
|
+use FTTHBundle\Entity\NAP;
|
|
|
+
|
|
|
+use Symfony\Component\Form\Extension\Core\Type\TextType;
|
|
|
+use Symfony\Component\Form\Extension\Core\Type\DateType;
|
|
|
+use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
|
|
+use WebserviceBundle\Form\Type\RemoteClientType;
|
|
|
+use MapBundle\Form\Type\RemoteMapType;
|
|
|
+use FOS\RestBundle\Controller\Annotations\RouteResource;
|
|
|
|
|
|
/**
|
|
|
* ONU controller.
|
|
@@ -16,6 +25,144 @@ use Symfony\Component\HttpFoundation\Request;
|
|
|
class ONUController extends Controller
|
|
|
{
|
|
|
|
|
|
+ public function importAction()
|
|
|
+ {
|
|
|
+ $adminPool = $this->get('sonata.admin.pool');
|
|
|
+ $webservice = $this->get("webservice");
|
|
|
+ $translator = $this->get('translator');
|
|
|
+ $flashbag = $this->get('session')->getFlashBag();
|
|
|
+
|
|
|
+ $urlObjects = $this->container->hasParameter('remote_get_objects_url');
|
|
|
+ $urlObjectTypes = $this->container->hasParameter('remote_get_object_type_url');
|
|
|
+ $_types = array();
|
|
|
+ $disabled = false;
|
|
|
+ $objectTypeId = 0;
|
|
|
+
|
|
|
+ if(!$urlObjects) {
|
|
|
+ $flashbag->add("error", $translator->trans("msg_no_defined_ftth_url",array(),"FTTHBundle"));
|
|
|
+ $disabled = true;
|
|
|
+ } else {
|
|
|
+ if(!$urlObjectTypes) {
|
|
|
+ $flashbag->add("error", $translator->trans("msg_no_defined_ftth_url",array(),"FTTHBundle"));
|
|
|
+ $disabled = true;
|
|
|
+ } else {
|
|
|
+ $urlObjectTypes = $this->getParameter('remote_get_object_type_url');
|
|
|
+ $filters = array('name' => 'ONU');
|
|
|
+ $_types = $webservice->getData($urlObjectTypes, $filters, array(), null, null);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(empty($_types)) {
|
|
|
+ $flashbag->add("error", $translator->trans("msg_no_onu_in_map",array(),"FTTHBundle"));
|
|
|
+ $disabled = true;
|
|
|
+ $objectTypeId = 0;
|
|
|
+ } else {
|
|
|
+ $disabled = false;
|
|
|
+ $objectTypeId = $_types[0]['id'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $form = $this->createFormBuilder()
|
|
|
+ ->add('mapId', RemoteMapType::class, array('label' => $translator->trans("form.label_map",array(),"FTTHBundle"), 'disabled' => $disabled))
|
|
|
+ ->add('clientId', RemoteClientType::class, array('label' => $translator->trans("form.label_client",array(),"FTTHBundle"), 'disabled' => $disabled))
|
|
|
+ ->getForm();
|
|
|
+
|
|
|
+ $flashbag->add("warning", $translator->trans("msg_select_map",array(),"FTTHBundle"));
|
|
|
+
|
|
|
+ return $this->render('FTTHBundle:ONU:onu_import.html.twig', array(
|
|
|
+ 'base_template' => $adminPool->getTemplate('layout'),
|
|
|
+ 'admin_pool' => $adminPool,
|
|
|
+ 'admin' => $adminPool->getAdminByClass("FTTHBundle\Entity\ONU"),
|
|
|
+ 'objectTypeId' => $objectTypeId,
|
|
|
+ 'form' => $form->createView(),
|
|
|
+ 'disabled' => $disabled
|
|
|
+ ));
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /*
|
|
|
+ * Queda pendiente enviar un comando para actualizar masivamente los devices
|
|
|
+ * /admin/ftth/onu/onu_save?_=1508847664462&limit=100&mapId=3&offset=0&clientId=1
|
|
|
+ */
|
|
|
+ public function onuSaveAction(Request $request)
|
|
|
+ {
|
|
|
+ $em = $this->get('doctrine')->getManager();
|
|
|
+ $webservice = $this->get("webservice");
|
|
|
+ $tenancy_service = $this->get("base_tenancy.tenancy_service");
|
|
|
+
|
|
|
+ $mapId = $request->get('mapId');
|
|
|
+ $clientId = $request->get('clientId');
|
|
|
+
|
|
|
+ if(is_null($mapId) || empty($mapId) || is_null($clientId) || empty($clientId)) {
|
|
|
+ $response = new Response(
|
|
|
+ json_encode(array()),
|
|
|
+ Response::HTTP_OK,
|
|
|
+ array('content-type' => 'application/json')
|
|
|
+ );
|
|
|
+
|
|
|
+ return $response;
|
|
|
+ }
|
|
|
+
|
|
|
+ $limit = $request->get('limit');
|
|
|
+ $offset = $request->get('offset');
|
|
|
+ $objectTypeId = $request->get('objectTypeId');
|
|
|
+
|
|
|
+ $urlObjectTypes = $this->getParameter('remote_get_objects_url');
|
|
|
+
|
|
|
+ $filters = array('type' => $objectTypeId, 'map' => $mapId);
|
|
|
+ $_onus = $webservice->getData($urlObjectTypes, $filters, array(), $limit, $offset);
|
|
|
+
|
|
|
+ $return = array();
|
|
|
+ foreach($_onus as $onu) {
|
|
|
+ $object = $em->getRepository("FTTHBundle:ONU")->findOneByPonSerialNumber($onu['text']);
|
|
|
+ if(is_null($object)) {
|
|
|
+ $object = new ONU();
|
|
|
+ $object->setClientId($clientId);
|
|
|
+ $object->setTenancyId($tenancy_service->getTenancyIdCurrent());
|
|
|
+ $object->setPonSerialNumber($onu['text']);
|
|
|
+ $em->persist($object);
|
|
|
+ $em->flush();
|
|
|
+ $return[] = "ONU create {$onu['text']}";
|
|
|
+ }
|
|
|
+
|
|
|
+ $location = $object->getLocation();
|
|
|
+ $action = "update";
|
|
|
+ if(is_null($location)) {
|
|
|
+ $location = new Location();
|
|
|
+ $em->persist($location);
|
|
|
+ $em->flush();
|
|
|
+ $object->setLocation($location);
|
|
|
+ $action = "create";
|
|
|
+ }
|
|
|
+
|
|
|
+ $data = json_decode($onu['vector']['data'],true);
|
|
|
+ $mapLocation = $data[0];
|
|
|
+ $mapLocation['zoom'] = 17;
|
|
|
+ $mapLocation['onu'] = "{$object->getPonSerialNumber()}";
|
|
|
+ $mapLocation['map_object_id'] = $onu['id'];
|
|
|
+
|
|
|
+ $location->setJsonExtraData($mapLocation);
|
|
|
+ $location->setObjectTypeId($objectTypeId);
|
|
|
+ $location->setMapId($mapId);
|
|
|
+
|
|
|
+ $em->persist($location);
|
|
|
+
|
|
|
+ $return[] = "LOCATION (id {$location->getId()}) {$action} - ONU (id {$object->getId()}) {$onu['text']} - ".json_encode($mapLocation);
|
|
|
+ }
|
|
|
+
|
|
|
+ $em->flush();
|
|
|
+
|
|
|
+ $response = new Response(
|
|
|
+ json_encode($return),
|
|
|
+ Response::HTTP_OK,
|
|
|
+ array('content-type' => 'application/json')
|
|
|
+ );
|
|
|
+
|
|
|
+ return $response;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* @param Request $request
|
|
|
* @return JsonResponse
|