Loading module/Import/config/import.config.php +34 −5 Changes for module/Import/config/import.config.php: 34 added lines, 5 removed lines. Original line number Diff line number Diff line Loading @@ -20,6 +20,8 @@ return [ 'import-all', 'update-these', 'index', 'apiInfo', 'launcher', 'info-last-update', ], 'roles' => [ Loading Loading @@ -91,7 +93,7 @@ return [ ], 'router' => [ 'routes' => [ 'home-import' => [ 'ws-import' => [ 'type' => 'Literal', 'may_terminate' => true, 'options' => [ Loading @@ -102,6 +104,28 @@ return [ ], ], 'child_routes' => [ 'api-info' => [ 'type' => Segment::class, 'may_terminate' => true, 'options' => [ 'route' => '/api-info/:etablissement', 'defaults' => [ 'controller' => Import\Controller\ImportController::class, 'action' => 'apiInfo', ], ], ], 'launcher' => [ 'type' => Literal::class, 'may_terminate' => true, 'options' => [ 'route' => '/launcher', 'defaults' => [ 'controller' => Import\Controller\ImportController::class, 'action' => 'launcher', ], ], ], 'info-last-update' => [ 'type' => Segment::class, 'may_terminate' => true, Loading Loading @@ -180,14 +204,19 @@ return [ 'default' => [ 'home' => [ 'pages' => [ 'ws' => [ 'ws-import' => [ 'label' => "Import", 'order' => 0, 'route' => 'home-import', 'route' => 'ws-import', 'pages' => [ 'problems' => [ 'home' => [ 'label' => "Accueil", 'route' => 'ws-import', 'resource' => \UnicaenAuth\Guard\PrivilegeController::getResourceId('Import\Controller\Import', 'index'), ], 'launcher' => [ 'label' => "Lancement", 'route' => 'home-import', 'route' => 'ws-import/launcher', 'resource' => \UnicaenAuth\Guard\PrivilegeController::getResourceId('Import\Controller\Import', 'index'), ], ], Loading module/Import/src/Import/Controller/Factory/ImportControllerFactory.php +30 −2 Changes for module/Import/src/Import/Controller/Factory/ImportControllerFactory.php: 30 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -3,18 +3,25 @@ namespace Import\Controller\Factory; use Application\Service\These\TheseService; use Assert\Assertion; use Assert\AssertionFailedException; use Doctrine\ORM\EntityManager; use Import\Controller\ImportController; use Import\Service\ImportService; use UnicaenApp\Exception\RuntimeException; use Zend\Mvc\Controller\ControllerManager; use Zend\ServiceManager\ServiceLocatorInterface; class ImportControllerFactory { public function __invoke(ControllerManager $serviceLocator) /** * @param ControllerManager $controllerManager * @return ImportController */ public function __invoke(ControllerManager $controllerManager) { /** @var ServiceLocatorInterface $parentLocator */ $parentLocator = $serviceLocator->getServiceLocator(); $parentLocator = $controllerManager->getServiceLocator(); /** @var EntityManager $entityManager */ $entityManager = $parentLocator->get('doctrine.entitymanager.orm_default'); Loading @@ -25,11 +32,32 @@ class ImportControllerFactory /** @var TheseService $theseService */ $theseService = $parentLocator->get('TheseService'); try { $config = $this->getConfig($controllerManager->getServiceLocator()); } catch (AssertionFailedException $e) { throw new RuntimeException("Configuration invalide", null, $e); } $controller = new ImportController(); $controller->setEntityManager($entityManager); $controller->setImportService($importService); $controller->setTheseService($theseService); $controller->setConfig($config); return $controller; } /** * @param ServiceLocatorInterface $sl * @return array * @throws \Assert\AssertionFailedException */ private function getConfig(ServiceLocatorInterface $sl) { $config = $sl->get('config'); Assertion::keyIsset($config, 'import-api'); return $config['import-api']; } } No newline at end of file module/Import/src/Import/Controller/ImportController.php +49 −4 Changes for module/Import/src/Import/Controller/ImportController.php: 49 added lines, 4 removed lines. Original line number Diff line number Diff line Loading @@ -6,6 +6,8 @@ use Application\Entity\Db\These; use Application\Filter\EtablissementPrefixFilter; use Application\Service\Etablissement\EtablissementServiceAwareTrait; use Application\Service\These\TheseServiceAwareTrait; use Assert\Assertion; use Import\Exception\CallException as ImportCallException; use Import\Service\Traits\ImportServiceAwareTrait; use UnicaenApp\Exception\LogicException; use UnicaenApp\Exception\RuntimeException; Loading @@ -23,17 +25,60 @@ class ImportController extends AbstractActionController use TheseServiceAwareTrait; use EtablissementServiceAwareTrait; /** * @var array $config [ 'CODE_ETABLISSEMENT' => [...] ] */ protected $config; /** * @param array $config */ public function setConfig($config) { $this->config = $config; } /** * @return ViewModel * @throws \Assert\AssertionFailedException */ public function indexAction() { $connection = $this->entityManager->getConnection(); $result = $connection->executeQuery("SELECT REQ_END_DATE FROM API_LOG WHERE REQ_ETABLISSEMENT='UCN' AND REQ_TABLE='variable' ORDER BY REQ_END_DATE DESC"); $last = $result->fetch()["REQ_END_DATE"]; Assertion::keyIsset($this->config, 'etablissements'); $codesEtablissements = array_keys($this->config['etablissements']); return new ViewModel([ 'last' => $last, 'codesEtablissements' => $codesEtablissements, ]); } public function apiInfoAction() { $etablissement = $this->params()->fromRoute("etablissement"); try { $version = $this->importService->getApiVersion($etablissement); $error = null; } catch (ImportCallException $e) { $version = "Inconnue"; $error = $e->getMessage() . " : " . $e->getPrevious()->getMessage(); } return [ 'version' => $version, 'error' => $error, ]; } public function launcherAction() { return new ViewModel(); } /** * @return ViewModel * @throws \Doctrine\DBAL\DBALException */ public function infoLastUpdateAction() { $etablissement = $this->params()->fromRoute("etablissement"); Loading module/Import/src/Import/Service/CallService.php +25 −30 Changes for module/Import/src/Import/Service/CallService.php: 25 added lines, 30 removed lines. Original line number Diff line number Diff line Loading @@ -21,32 +21,24 @@ class CallService use LoggerAwareTrait; /** * $config est fourni par la factory et permet l'acces à la config * * @var array $config * @var array */ protected $config; /** * les quatres variables $url, $code, $user et $password sont des données de configuration pour l'acces au Web * Service * * @var string $url : le chemin d'acces au web service * @var string $user : l'identifiant pour l'authentification * @var string $password : le mot de passe pour l'authentification * @var string|null $proxy : le champ proxy * @var boolean|string $verify : le champ pour le mode https * @var float $timeout : timeout of the request in seconds */ protected $url; protected $user; protected $password; protected $proxy; protected $verify = true; /** * @var array */ protected $logs = []; protected $timeout = 0; /** * @param array $config Loading Loading @@ -80,14 +72,6 @@ class CallService return $json; } /** * @return array [DateTime, string] le log associé pour l'affichage */ public function getLogs() { return $this->logs; } /** * @param string $uri * @return \stdClass Loading Loading @@ -131,17 +115,12 @@ class CallService if (array_key_exists('verify', $this->config)) { $this->verify = $this->config['verify']; } if (array_key_exists('timeout', $this->config)) { $this->timeout = $this->config['timeout']; } } /** * Appel du Web Service d'import de données. * * @param string $uri : la "page" du Web Service à interroger * @return Response la réponse du Web Service * * RMQ le client est configuré en utilisant les propriétés du FetcherService */ private function sendRequest($uri) private function createClient() { try { $this->loadConfig(); Loading @@ -162,12 +141,28 @@ class CallService } else { $options['proxy'] = ['no' => 'localhost']; } if ($this->verify !== null) { $options['verify'] = $this->verify; } if ($this->timeout !== null) { $options['timeout'] = $this->timeout; } return new Client($options); } /** * Appel du Web Service d'import de données. * * @param string $uri : la "page" du Web Service à interroger * @return Response la réponse du Web Service * * RMQ le client est configuré en utilisant les propriétés du FetcherService */ private function sendRequest($uri) { $client = $this->createClient(); $client = new Client($options); try { $_debut = microtime(true); $response = $client->request('GET', $uri); Loading module/Import/src/Import/Service/Factory/ImportServiceFactory.php +2 −1 Changes for module/Import/src/Import/Service/Factory/ImportServiceFactory.php: 2 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ use Import\Service\FetcherService; use Import\Service\ImportService; use Import\Service\SynchroService; use Zend\Log\Logger; use Zend\Log\Writer\Noop; use Zend\ServiceManager\ServiceLocatorInterface as ContainerInterface; class ImportServiceFactory Loading @@ -26,7 +27,7 @@ class ImportServiceFactory /** @var EtablissementService $etbalissementService */ $etbalissementService = $container->get(EtablissementService::class); $logger = new Logger(); $logger = (new Logger())->addWriter(new Noop()); $service = new ImportService(); $service->setFetcherService($fetcherService); Loading Loading
module/Import/config/import.config.php +34 −5 Changes for module/Import/config/import.config.php: 34 added lines, 5 removed lines. Original line number Diff line number Diff line Loading @@ -20,6 +20,8 @@ return [ 'import-all', 'update-these', 'index', 'apiInfo', 'launcher', 'info-last-update', ], 'roles' => [ Loading Loading @@ -91,7 +93,7 @@ return [ ], 'router' => [ 'routes' => [ 'home-import' => [ 'ws-import' => [ 'type' => 'Literal', 'may_terminate' => true, 'options' => [ Loading @@ -102,6 +104,28 @@ return [ ], ], 'child_routes' => [ 'api-info' => [ 'type' => Segment::class, 'may_terminate' => true, 'options' => [ 'route' => '/api-info/:etablissement', 'defaults' => [ 'controller' => Import\Controller\ImportController::class, 'action' => 'apiInfo', ], ], ], 'launcher' => [ 'type' => Literal::class, 'may_terminate' => true, 'options' => [ 'route' => '/launcher', 'defaults' => [ 'controller' => Import\Controller\ImportController::class, 'action' => 'launcher', ], ], ], 'info-last-update' => [ 'type' => Segment::class, 'may_terminate' => true, Loading Loading @@ -180,14 +204,19 @@ return [ 'default' => [ 'home' => [ 'pages' => [ 'ws' => [ 'ws-import' => [ 'label' => "Import", 'order' => 0, 'route' => 'home-import', 'route' => 'ws-import', 'pages' => [ 'problems' => [ 'home' => [ 'label' => "Accueil", 'route' => 'ws-import', 'resource' => \UnicaenAuth\Guard\PrivilegeController::getResourceId('Import\Controller\Import', 'index'), ], 'launcher' => [ 'label' => "Lancement", 'route' => 'home-import', 'route' => 'ws-import/launcher', 'resource' => \UnicaenAuth\Guard\PrivilegeController::getResourceId('Import\Controller\Import', 'index'), ], ], Loading
module/Import/src/Import/Controller/Factory/ImportControllerFactory.php +30 −2 Changes for module/Import/src/Import/Controller/Factory/ImportControllerFactory.php: 30 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -3,18 +3,25 @@ namespace Import\Controller\Factory; use Application\Service\These\TheseService; use Assert\Assertion; use Assert\AssertionFailedException; use Doctrine\ORM\EntityManager; use Import\Controller\ImportController; use Import\Service\ImportService; use UnicaenApp\Exception\RuntimeException; use Zend\Mvc\Controller\ControllerManager; use Zend\ServiceManager\ServiceLocatorInterface; class ImportControllerFactory { public function __invoke(ControllerManager $serviceLocator) /** * @param ControllerManager $controllerManager * @return ImportController */ public function __invoke(ControllerManager $controllerManager) { /** @var ServiceLocatorInterface $parentLocator */ $parentLocator = $serviceLocator->getServiceLocator(); $parentLocator = $controllerManager->getServiceLocator(); /** @var EntityManager $entityManager */ $entityManager = $parentLocator->get('doctrine.entitymanager.orm_default'); Loading @@ -25,11 +32,32 @@ class ImportControllerFactory /** @var TheseService $theseService */ $theseService = $parentLocator->get('TheseService'); try { $config = $this->getConfig($controllerManager->getServiceLocator()); } catch (AssertionFailedException $e) { throw new RuntimeException("Configuration invalide", null, $e); } $controller = new ImportController(); $controller->setEntityManager($entityManager); $controller->setImportService($importService); $controller->setTheseService($theseService); $controller->setConfig($config); return $controller; } /** * @param ServiceLocatorInterface $sl * @return array * @throws \Assert\AssertionFailedException */ private function getConfig(ServiceLocatorInterface $sl) { $config = $sl->get('config'); Assertion::keyIsset($config, 'import-api'); return $config['import-api']; } } No newline at end of file
module/Import/src/Import/Controller/ImportController.php +49 −4 Changes for module/Import/src/Import/Controller/ImportController.php: 49 added lines, 4 removed lines. Original line number Diff line number Diff line Loading @@ -6,6 +6,8 @@ use Application\Entity\Db\These; use Application\Filter\EtablissementPrefixFilter; use Application\Service\Etablissement\EtablissementServiceAwareTrait; use Application\Service\These\TheseServiceAwareTrait; use Assert\Assertion; use Import\Exception\CallException as ImportCallException; use Import\Service\Traits\ImportServiceAwareTrait; use UnicaenApp\Exception\LogicException; use UnicaenApp\Exception\RuntimeException; Loading @@ -23,17 +25,60 @@ class ImportController extends AbstractActionController use TheseServiceAwareTrait; use EtablissementServiceAwareTrait; /** * @var array $config [ 'CODE_ETABLISSEMENT' => [...] ] */ protected $config; /** * @param array $config */ public function setConfig($config) { $this->config = $config; } /** * @return ViewModel * @throws \Assert\AssertionFailedException */ public function indexAction() { $connection = $this->entityManager->getConnection(); $result = $connection->executeQuery("SELECT REQ_END_DATE FROM API_LOG WHERE REQ_ETABLISSEMENT='UCN' AND REQ_TABLE='variable' ORDER BY REQ_END_DATE DESC"); $last = $result->fetch()["REQ_END_DATE"]; Assertion::keyIsset($this->config, 'etablissements'); $codesEtablissements = array_keys($this->config['etablissements']); return new ViewModel([ 'last' => $last, 'codesEtablissements' => $codesEtablissements, ]); } public function apiInfoAction() { $etablissement = $this->params()->fromRoute("etablissement"); try { $version = $this->importService->getApiVersion($etablissement); $error = null; } catch (ImportCallException $e) { $version = "Inconnue"; $error = $e->getMessage() . " : " . $e->getPrevious()->getMessage(); } return [ 'version' => $version, 'error' => $error, ]; } public function launcherAction() { return new ViewModel(); } /** * @return ViewModel * @throws \Doctrine\DBAL\DBALException */ public function infoLastUpdateAction() { $etablissement = $this->params()->fromRoute("etablissement"); Loading
module/Import/src/Import/Service/CallService.php +25 −30 Changes for module/Import/src/Import/Service/CallService.php: 25 added lines, 30 removed lines. Original line number Diff line number Diff line Loading @@ -21,32 +21,24 @@ class CallService use LoggerAwareTrait; /** * $config est fourni par la factory et permet l'acces à la config * * @var array $config * @var array */ protected $config; /** * les quatres variables $url, $code, $user et $password sont des données de configuration pour l'acces au Web * Service * * @var string $url : le chemin d'acces au web service * @var string $user : l'identifiant pour l'authentification * @var string $password : le mot de passe pour l'authentification * @var string|null $proxy : le champ proxy * @var boolean|string $verify : le champ pour le mode https * @var float $timeout : timeout of the request in seconds */ protected $url; protected $user; protected $password; protected $proxy; protected $verify = true; /** * @var array */ protected $logs = []; protected $timeout = 0; /** * @param array $config Loading Loading @@ -80,14 +72,6 @@ class CallService return $json; } /** * @return array [DateTime, string] le log associé pour l'affichage */ public function getLogs() { return $this->logs; } /** * @param string $uri * @return \stdClass Loading Loading @@ -131,17 +115,12 @@ class CallService if (array_key_exists('verify', $this->config)) { $this->verify = $this->config['verify']; } if (array_key_exists('timeout', $this->config)) { $this->timeout = $this->config['timeout']; } } /** * Appel du Web Service d'import de données. * * @param string $uri : la "page" du Web Service à interroger * @return Response la réponse du Web Service * * RMQ le client est configuré en utilisant les propriétés du FetcherService */ private function sendRequest($uri) private function createClient() { try { $this->loadConfig(); Loading @@ -162,12 +141,28 @@ class CallService } else { $options['proxy'] = ['no' => 'localhost']; } if ($this->verify !== null) { $options['verify'] = $this->verify; } if ($this->timeout !== null) { $options['timeout'] = $this->timeout; } return new Client($options); } /** * Appel du Web Service d'import de données. * * @param string $uri : la "page" du Web Service à interroger * @return Response la réponse du Web Service * * RMQ le client est configuré en utilisant les propriétés du FetcherService */ private function sendRequest($uri) { $client = $this->createClient(); $client = new Client($options); try { $_debut = microtime(true); $response = $client->request('GET', $uri); Loading
module/Import/src/Import/Service/Factory/ImportServiceFactory.php +2 −1 Changes for module/Import/src/Import/Service/Factory/ImportServiceFactory.php: 2 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ use Import\Service\FetcherService; use Import\Service\ImportService; use Import\Service\SynchroService; use Zend\Log\Logger; use Zend\Log\Writer\Noop; use Zend\ServiceManager\ServiceLocatorInterface as ContainerInterface; class ImportServiceFactory Loading @@ -26,7 +27,7 @@ class ImportServiceFactory /** @var EtablissementService $etbalissementService */ $etbalissementService = $container->get(EtablissementService::class); $logger = new Logger(); $logger = (new Logger())->addWriter(new Noop()); $service = new ImportService(); $service->setFetcherService($fetcherService); Loading