Explorar o código

Se mueve supports a atributo de la entidad workflow, se quita del template y se modifica la validación. Se agrega para las vistas y atributo en entidad. Se agrega al evento que realiza las acciones del workflow la posibilidad de enviar el template a renderizar junto con la entidad al rabbit.

Maximiliano Schvindt %!s(int64=8) %!d(string=hai) anos
pai
achega
f6bab71569

+ 11 - 0
Admin/WorkflowAdmin.php

@@ -8,6 +8,7 @@ use Sonata\AdminBundle\Datagrid\ListMapper;
 use Sonata\AdminBundle\Form\FormMapper;
 use Sonata\AdminBundle\Show\ShowMapper;
 use Symfony\Component\Yaml\Yaml;
+use WorkflowBundle\Utils\WorkFlowEntityClasses;
 
 class WorkflowAdmin extends BaseAdmin
 {
@@ -63,6 +64,14 @@ class WorkflowAdmin extends BaseAdmin
     protected function configureFormFields(FormMapper $formMapper)
     {
 
+        $_supports = WorkFlowEntityClasses::getClass();
+        $supports = array();
+        foreach($_supports as $key => $class) {
+            if(class_exists($key)) {
+                $supports[$key] = $key;
+            }
+        }
+        
         $formMapper
             ->add('name')
             ->add('description')
@@ -70,6 +79,7 @@ class WorkflowAdmin extends BaseAdmin
             ->add('type', 'choice', array('choices' => array('state_machine' => 'state_machine', 'workflow' => 'workflow')))
             ->add('markingType', 'choice', array('choices' => array('single_state' => 'single_state', 'multiple_state' => 'multiple_state')))
             ->add('markingName', 'choice', array('choices' => array('currentState' => 'currentState')))
+            ->add('support', 'choice', array('choices' => $supports,'multiple'   => true, 'required' => true))
             ->add('template', null, array('attr' => array('style' => 'height:500px;')))
 
             ->setHelps(array(
@@ -97,6 +107,7 @@ class WorkflowAdmin extends BaseAdmin
             ->add('type')
             ->add('markingType')
             ->add('markingName')
+            ->add('support')
             ->add('template','string', array('template' => 'WorkflowBundle:Workflow:show_template.html.twig'))
         ;
     }

+ 1 - 0
Command/WorkflowGenerateListCommand.php

@@ -47,6 +47,7 @@ class WorkflowGenerateListCommand extends ContainerAwareCommand
                $markingName = array(0 => $workflow->getMarkingName());
             }
             $body['marking_store'] = array('type' => $workflow->getMarkingType(), 'arguments' => $markingName);
+            $body['supports'] = $workflow->getSupport();
 
             $body += Yaml::parse($workflow->getTemplate());
 

+ 29 - 2
Entity/Workflow.php

@@ -101,10 +101,16 @@ class Workflow
      */
     protected $enable = true;
     
+    /**
+     * @ORM\Column(type="array", nullable=true)
+     *
+     */
+    protected $support = array();
+    
     
     public function __construct()
     {
-        
+        $this->support = array();
     }
 
     /**
@@ -399,6 +405,7 @@ class Workflow
                $markingName = array(0 => $workflow->getMarkingName());
             }
             $body['marking_store'] = array('type' => $workflow->getMarkingType(), 'arguments' => $markingName);
+            $body['supports'] = $workflow->getSupport();
 
             $body += Yaml::parse($workflow->getTemplate());
 
@@ -461,8 +468,28 @@ class Workflow
         
         return $definition->getInitialPlace();
 
-        
+    }
 
+    /**
+     * Set support
+     *
+     * @param array $support
+     * @return Workflow
+     */
+    public function setSupport($support)
+    {
+        $this->support = $support;
+        return $this;
+    }
+
+    /**
+     * Get support
+     *
+     * @return array
+     */
+    public function getSupport()
+    {
+        return $this->support;
     }
 
 }

+ 9 - 3
Event/EventSubscriber.php

@@ -5,6 +5,7 @@ namespace WorkflowBundle\Event;
 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
 use Symfony\Component\Workflow\Event\Event;
 use Symfony\Component\Workflow\Event\GuardEvent;
+use WorkflowBundle\Services\ProducerService;
 use Symfony\Component\DependencyInjection\ContainerInterface;
 
 # Ayuda:
@@ -17,13 +18,15 @@ class EventSubscriber implements EventSubscriberInterface
 {
 
     private $container;
+    private $producerService;
 
     /**
      * @param ContainerInterface $container
      */
-    public function __construct(ContainerInterface $container)
+    public function __construct(ContainerInterface $container, ProducerService $producerService)
     {
         $this->container = $container;
+        $this->producerService = $producerService;
     }
 
     public static function getSubscribedEvents()
@@ -111,12 +114,15 @@ class EventSubscriber implements EventSubscriberInterface
     public function completeAction($action, $params) {
         
         $logger = $this->container->get('logger');
-        $template = $action->getTemplate();
 
+        $object = $params['entity'];
+        $this->producerService->publishMessage($action, $object);
+
+        
+        $template = $action->getTemplate();
         $twig = new \Twig_Environment(new \Twig_Loader_String());
         $rendered = $twig->render($template, $params);
 
-        $object = $params['entity'];
         $class = get_class($object);
         
         $logger->info("WORKFLOW-ACTION {$class}_id_{$object->getId()} | action_id_{$action->getId()} => Render: {$rendered}");

+ 1 - 1
Resources/config/services.yml

@@ -34,7 +34,7 @@ services:
         class: WorkflowBundle\Event\EventSubscriber
         tags:
             - { name: kernel.event_subscriber }
-        arguments: ['@service_container']
+        arguments: ['@service_container','@workflow.producer_service']
     workflow.twig_extension:
         class: WorkflowBundle\Twig\WorkflowExtension
         tags:

+ 4 - 0
Resources/translations/WorkflowBundle.es.yml

@@ -14,6 +14,7 @@ filter:
     label_event_reference : Referencia
     label_actions: Actions
     label_entity_class: Entidad
+    label_support: Supports
 breadcrumb:
     link_workflow_list: Listado Workflows
     link_workflow_create: Crear Workflow
@@ -43,6 +44,7 @@ form:
     label_event_reference : Referencia
     label_actions: Actions
     label_entity_class: Entidad
+    label_support: Supports
 list:
     label_id: Id
     label_name: Nombre
@@ -62,6 +64,7 @@ list:
     label_event_reference : Referencia
     label_actions: Actions
     label_entity_class: Entidad
+    label_support: Supports
 show:
     label_id: Id
     label_name: Nombre
@@ -81,6 +84,7 @@ show:
     label_event_reference : Referencia
     label_actions: Actions
     label_entity_class: Entidad
+    label_support: Supports
 helps:
     workflow_label_name: Nombre con el que se identificará el workflow. Se convertirá a minúscula y los espacios se reemplazarán por "_"
     workflow_label_type: "Tipo de Workflow: state_machine o workflow"

+ 7 - 0
Utils/WorkFlowEntityClasses.php

@@ -16,5 +16,12 @@ class WorkFlowEntityClasses
     const FTTH_ONU = 'FTTHBundle\Entity\ONU';
 
     const FTTH_OLT = 'FTTHBundle\Entity\OLT';
+    
+    const BASE_CLIENT = 'ClientBundle\Entity\Client';
+
+    public function getClass() 
+    {
+        return array(self::FTTH_ONU => self::FTTH_ONU, self::FTTH_OLT => self::FTTH_OLT, self::BASE_CLIENT => self::BASE_CLIENT);
+    }
 
 }

+ 6 - 7
Validator/Constraints/ContainsYamlValidator.php

@@ -15,12 +15,13 @@ class ContainsYamlValidator extends ConstraintValidator
 {
     public function validate($value, Constraint $constraint)
     {
-        $valids_keys = array("supports","initial_place","places","transitions");
+        $valids_keys = array("initial_place","places","transitions");
 
         $object = $this->context->getObject();
         $type = $object->getType();
         $markingType = $object->getMarkingType();
-        $name = $this->context->getObject();;
+        $name = $this->context->getObject();
+        $supports = $object->getSupport();
 
         //Validate Format YAML
         try {
@@ -53,13 +54,11 @@ class ContainsYamlValidator extends ConstraintValidator
         }
 
         //Validate Template SUPPORTS
-        if(isset($yaml['supports'])) {
-            if(!is_array($yaml['supports'])) {
-                $this->context->buildViolation("errors.workflow_template_supports_error")->setParameter('%string%', "")->addViolation();
-            } elseif(count($yaml['supports']) == 0) {
+        if(!is_null($supports)) {
+            if(count($supports) == 0) {
                 $this->context->buildViolation("errors.workflow_template_supports_empty")->setParameter('%string%', "")->addViolation();
             } else {
-                foreach($yaml['supports'] as $k => $class) {
+                foreach($supports as $k => $class) {
                     if(!class_exists($class)) {
                         $this->context->buildViolation("errors.workflow_template_supports_class_error")->setParameter('%class%', $class)->addViolation();
                     }