Browse Source

apply web service

Luciano Andrade 7 years ago
parent
commit
de146f833f

+ 1 - 1
.drone.yml

@@ -35,7 +35,7 @@ pipeline:
       - composer dump-autoload --optimize
       - chmod 0777 -R var/logs var/cache var/sessions
       - php bin/console doctrine:schema:update --force -vvv --env=test
-      - touch var/logs/{dev,test}.log
+      - touch var/logs/test.log
       - tail -f var/logs/*.log &
       - vendor/phpunit/phpunit/phpunit -c phpunit.xml.dist
 

+ 34 - 0
src/FTTHBundle/Controller/ONURESTController.php

@@ -12,6 +12,8 @@ use Symfony\Component\HttpFoundation\Request;
 use Symfony\Component\HttpFoundation\Response;
 use WebserviceBundle\Controller\RESTController;
 
+use FOS\RestBundle\Controller\Annotations\Patch;
+
 /**
  * ONU controller.
  * @RouteResource("ONU")
@@ -131,4 +133,36 @@ class ONURESTController extends RESTController
 //        }
 //    }
 
+    /**
+     * PATCH Route annotation.
+     * @Patch("/onus/apply/{id}/{workflow}/{transition}")
+     * @View(statusCode=201, serializerEnableMaxDepthChecks=true)
+     *
+     * @param Request $request
+     * @param $entity
+     * @param $transition
+     * @param $workflow
+     *
+     * @return Response
+     */
+    public function applyAction(Request $request, ONU $entity, String $workflow, String $transition)
+    {
+        try {
+
+	    $wr = $this->container->get("workflow.registry");
+	    $wf = $wr->get($entity, $workflow);
+
+	    $newState = $wf->apply($entity, $transition);
+
+	    $em = $this->container->get("doctrine.orm.entity_manager");
+	    $em->persist($entity);
+	    $em->flush();
+
+	    return $entity;
+
+        } catch (\Exception $e) {
+            return FOSView::create($e->getMessage(), Codes::HTTP_INTERNAL_SERVER_ERROR);
+        }
+    }
+
 }

+ 2 - 2
src/FTTHBundle/Form/ONUType.php

@@ -41,8 +41,8 @@ class ONUType extends AbstractType
             ->add('nap')
             ->add('ponSerialNumber')
             ->add('clientId')
-           ->add('administrativeState')
-           ->add('transitionState')
+           //->add('administrativeState')
+           //->add('transitionState')
             ->add('tenancyId');
 
         $builder->addEventListener(

+ 30 - 0
src/FTTHBundle/tests/ONURESTControllerTest.php

@@ -174,6 +174,36 @@ class ONURESTControllerTest extends WebTestCaseBase
         $this->assertContains('pon_modifi', strtolower($response->getContent()), "Error al buscar al onu modificado.");
     }
 
+    /**
+     * Aplica una transicion de un workflow a una entidad
+     * apply_onus -> /api/onu/apply/{id}/{workflow}/{transition}.{_format}
+     * controller: ClientBundle:ClientREST:cget
+     * Method: GET
+     */
+    public function testAPPLY()
+    {
+        $this->initDefault($this->obtainDataWebService());
+        $response = $this->generateGET();
+        // verifco el resultado
+        $this->assertEquals(200, $response->getStatusCode(), "Error en la respuesta http.");
+        $this->assertJson($json = $response->getContent(), "No se obtuvo un objeto json.");
+
+	$json = json_decode($json, true);
+	$json = $json[0];
+
+	$this->assertEquals("active", $json["administrativeState"]);
+
+	$this->getClient()->request('PATCH',
+		$this->getUriPutDelete(). "apply/". $json["id"] . "/administrative_state/active_to_suspend.json" , array());
+
+	$json = json_decode($response->getContent(), true);
+	$json = $json[0];
+
+	$this->assertEquals("suspend", $json["administrativeState"]);
+
+        $response = $this->getClient()->getResponse();
+	var_dump( $response->getStatusCode());
+    }
 
     /**
      * Realiza una baja.