public function execute($arguments = array(), $options = array())
 {
     $this->logSection('psdf:build-package', sprintf("Construyendo paquete '%s'", $arguments['macro_package']));
     $file = sfConfig::get('psdf_xpdl_dir') . '/' . $arguments['macro_package'];
     if (!file_exists($file)) {
         throw new sfCommandException(sprintf('No existe el archivo "%s".', $file));
     }
     $xpdl = new psdfXpdl($file);
     if (!$xpdl) {
         throw new sfCommandException(sprintf('No se pudo cargar xpdl "%s".', $file));
     }
     $info = explode('/', $arguments['macro_package']);
     $macro = str_replace(' ', '_', $info[0]);
     $package = str_replace(' ', '_', $xpdl->getPackageName());
     $this->logSection('psdf:build-package', sprintf("Nombre: '%s' Id: '%s'", $xpdl->getPackageName(), $xpdl->getPackageId()));
     // Obtengo procesos
     $process = $xpdl->getProcessArray();
     // Construyo cada proceso
     foreach ($process as $proc) {
         $task = new psdfBuildProcessTask($this->dispatcher, $this->formatter);
         $task->run(array($arguments['macro_package'], $proc['id']), $options);
     }
     $this->logSection('psdf:build-package', sprintf("Fin de la construcción del paquete '%s'", $arguments['macro_package']));
 }
 public function execute($arguments = array(), $options = array())
 {
     $this->logSection('psdf:build-process', sprintf("Construyendo proceso '%s'", $arguments['process']));
     $file = sfConfig::get('psdf_xpdl_dir') . '/' . $arguments['macro_package'];
     if (!file_exists($file)) {
         throw new sfCommandException(sprintf('No existe el archivo "%s".', $file));
     }
     $xpdl = new psdfXpdl($file);
     if (!$xpdl) {
         throw new sfCommandException(sprintf('No se pudo cargar xpdl "%s".', $file));
     }
     $info = explode('/', $arguments['macro_package']);
     $macro = str_replace(' ', '_', $info[0]);
     $package = str_replace(' ', '_', $xpdl->getPackageName());
     $this->logSection('psdf:build-process', sprintf("Nombre: '%s' Id: '%s'", $xpdl->getProcessName($arguments['process']), $xpdl->getProcessId($arguments['process'])));
     if (!$xpdl->processExist($arguments['process'])) {
         throw new sfCommandException(sprintf('No existe el proceso "%s" en el xpdl.', $arguments['process']));
     }
     // Si el Macro aún no fué generado, lo hago ahora
     if (!file_exists(sfConfig::get('sf_apps_dir') . '/' . $macro)) {
         $task = new psdfGenerateMacroTask($this->dispatcher, $this->formatter);
         $task->run(array($macro), array());
     }
     // Si el Paquete aún no fué generado, lo hago ahora
     if (!file_exists(sfConfig::get('sf_apps_dir') . '/' . $macro . '/modules/' . $package)) {
         $task = new psdfGeneratePackageTask($this->dispatcher, $this->formatter);
         $task->run(array($macro, $xpdl->getPackageName()), array());
     }
     // Obtengo datafiels, participantes y tipos de datos del paquete y proceso
     $data_pr['datafields'] = array_merge($xpdl->getDataFields(), $xpdl->getDataFields($arguments['process']));
     $data_pr['participants'] = array_merge($xpdl->getParticipants(), $xpdl->getParticipants($arguments['process']));
     $data_pr['type_declarations'] = $xpdl->getTypeDeclarations();
     // Parametros del proceso
     //$parameters = $this->xpdl->getParameters();
     // Recorro sus actividades
     $activities = $xpdl->getActivities($arguments['process']);
     foreach ($activities as $activity) {
         if ($activity['name'] == '') {
             throw new sfCommandException(sprintf("La actividad '%s' del tipo '%s' no tiene un nombre definido", $activity['id'], $activity['type']));
         }
         // Obtengo transiciones y patrones
         $data_ac['id'] = $activity['id'];
         $data_ac['type'] = $activity['type'];
         $data_ac['transitions'] = $xpdl->getTransitions($arguments['process'], $activity['id']);
         $data_ac['patterns'] = $xpdl->getPsdfPatterns($arguments['process'], $activity['id']);
         // Fuerzo el patron Foo si no se ha definido uno
         if (count($data_ac['patterns']) == 0) {
             $data_ac['patterns']['Foo']['Params'] = array();
         }
         $task = new psdfGenerateActivityTask($this->dispatcher, $this->formatter);
         $task->setProcessData($data_pr);
         // Fuerzo por acá los datos del proceso
         $task->setActivityData($data_ac);
         // Fuerzo por acá los datos del proceso
         $task->run(array($macro, $package, $xpdl->getProcessName($arguments['process']), $arguments['process'], $activity['name'], $activity['id']), $options);
     }
     $this->logSection('psdf:build-process', sprintf("Fin de la construccion proceso '%s'", $arguments['process']));
 }
Example #3
0
 public function executeSync(sfWebRequest $request)
 {
     // Preparo el id y name del proyecto para la proxima accion
     $this->proyecto = array();
     $this->proyecto['id'] = $request->getParameter('id');
     $proyecto = Doctrine::getTable('Proyecto')->find($request->getParameter('id'));
     $this->proyecto['name'] = $proyecto->getNombre();
     // Recupero en un array la lista de documentos xpdl
     $finder = sfFinder::type('file')->name('*.xpdl');
     $finder->ignore_version_control(true);
     $files = $finder->in(sfConfig::get('psdf_xpdl_dir'));
     // Armo otro array con informacion de los xpdl
     foreach ($files as $file) {
         $xpdl = new psdfXpdl();
         $ret = $xpdl->load($file);
         $new['nombre'] = $file;
         $new['macro'] = $ret ? $xpdl->getMacroName() : '';
         $new['package'] = $ret ? $xpdl->getPackageName() : '';
         $new['fecha'] = filemtime($file);
         $this->proyecto['files'][] = $new;
     }
     // Ordeno el array por la fecha de modificacion
     usort($this->proyecto['files'], array('self', 'comparar'));
 }
 /**
  * Procesa documentos xpdl, previamente seleccionados, generando y/o
  * actualizando objetos Macro, Paquete, Proceso, Actividad y RolAbstracto.
  * Retorna un array con los archivos que no pudieron ser procesados.
  *
  * @param array $files_xpdl Archivos Xpdls a Importar
  * @return array Archivos no procesados
  */
 public function processXpdls($files_xpdl = array())
 {
     // Para ir volcando los paquetes no procesados por alguna regla invalida
     $noimp = array();
     foreach ($files_xpdl as $file) {
         $xpdl = new psdfXpdl($file);
         // Recupero Id y Nombre del paquete
         $xpdlPackageId = $xpdl->getPackageId();
         $xpdlPackageName = $xpdl->getPackageName();
         // Recupero Macro
         $macro_name = $xpdl->getMacroName();
         // Contenido del xpdl como un string para guardarlo
         $content = $xpdl->getContent();
         // Intento recuperar Macro y Paquete si ya estuviesen almacenados
         $macro = Doctrine::getTable('Macro')->findOneByNombre($macro_name);
         $pack = Doctrine::getTable('Paquete')->findOneByXpdlId($xpdlPackageId);
         // REGLAS
         $err = array();
         // Si no se cumple alguna regla generar:
         // $err['file'] = $this->getNombre();
         // $err['error'] = 'Mensaje del error';
         // CONTINUO SI SE PASARON TODAS LAS REGLAS
         if (count($err) == 0) {
             // Creo el macro si aún no existe
             if (!$macro) {
                 $macro = new Macro();
                 $macro->setNombre($macro_name);
                 $macro->setRelProyecto($this->getId());
                 $macro->save();
             }
             // Creo el paquete si aún no existe y actualizo
             if (!$pack) {
                 $pack = new Paquete();
                 $pack->setNombre($xpdlPackageName);
                 $pack->setRelMacro($macro->getId());
                 $pack->setXpdl($content);
                 $pack->setXpdlId($xpdlPackageId);
                 $pack->save();
                 // Grabo para que genere el Id
             } else {
                 if ($pack->getXpdl() != $content) {
                     $pack->setXpdl($content);
                 }
                 if ($pack->getNombre() != $xpdlPackageName) {
                     $pack->setNombre($xpdlPackageName);
                 }
             }
             // Guardo el paquete con los cambios
             if ($pack->isNew() or $pack->isModified()) {
                 $pack->save();
             }
             // Delego en el paquete la sincronizacion de los Procesos
             $err = $pack->syncProcesses($xpdl);
             if (count($err) > 0) {
                 $noimp[] = array_merge($noimp, $err);
             }
         } else {
             $noimp[] = $err;
         }
     }
     return $noimp;
 }