Commit 55e6036e authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Refactorisation: extraction dans le service Doctorant d'un méthode de recherche par UserWrapper

parent b152abde
Loading
Loading
Loading
Loading
Loading
+2 −3
Changes for module/Application/config/others/doctorant.config.php: 2 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -3,8 +3,8 @@
use Application\Controller\Factory\DoctorantControllerFactory;
use Application\Provider\Privilege\DoctorantPrivileges;
use Application\Service\Doctorant\DoctorantService;
use Application\Service\Doctorant\DoctorantServiceFactory;
use UnicaenAuth\Guard\PrivilegeController;
use UnicaenAuth\Provider\Rule\PrivilegeRuleProvider;

return [
    'bjyauthorize'    => [
@@ -93,10 +93,9 @@ return [
    ),
    'service_manager' => [
        'invokables' => array(
            'DoctorantService' => DoctorantService::class,
        ),
        'factories' => [

            'DoctorantService' => DoctorantServiceFactory::class,
        ],
        'aliases' => [
            DoctorantService::class => 'DoctorantService',
+3
Changes for module/Application/config/others/etablissement.config.php: 3 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -161,6 +161,9 @@ return [
        ],
        'factories' => [
        ],
        'aliases' => [
            EtablissementService::class => 'EtablissementService',
        ]
    ],
    'controllers'     => [
        'invokables' => [
+1 −11
Changes for module/Application/src/Application/Authentication/Storage/AppStorage.php: 1 added line, 11 removed lines.
Original line number Diff line number Diff line
@@ -8,7 +8,6 @@ use Application\Entity\UserWrapper;
use Application\Service\Doctorant\DoctorantServiceAwareTrait;
use Application\Service\Etablissement\EtablissementServiceAwareTrait;
use Application\Service\Utilisateur\UtilisateurServiceAwareTrait;
use Doctrine\ORM\NonUniqueResultException;
use UnicaenApp\Exception\RuntimeException;
use UnicaenAuth\Authentication\Storage\ChainableStorage;
use UnicaenAuth\Authentication\Storage\ChainEvent;
@@ -106,16 +105,7 @@ class AppStorage implements ChainableStorage
            return $this->doctorant;
        }

        $id = $this->userWrapper->getSupannId();
        $domaineEtab = $this->userWrapper->getDomainFromEppn();
        $etablissement = $this->getEtablissementService()->getRepository()->findOneByDomaine($domaineEtab);
        $sourceCode = $etablissement->prependPrefixTo($id);

        try {
            $this->doctorant = $this->doctorantService->getRepository()->findOneBySourceCode($sourceCode);
        } catch (NonUniqueResultException $e) {
            throw new RuntimeException("Plusieurs doctorants ont été trouvés avec le même source code: " . $sourceCode);
        }
        $this->doctorant = $this->doctorantService->findOneByUserWrapper($this->userWrapper);

        return $this->doctorant;
    }
+1 −12
Changes for module/Application/src/Application/Provider/IdentityProvider.php: 1 added line, 12 removed lines.
Original line number Diff line number Diff line
@@ -14,8 +14,6 @@ use Application\Service\Role\RoleServiceAwareTrait;
use Application\Service\UniteRecherche\UniteRechercheServiceAwareTrait;
use Application\Service\Utilisateur\UtilisateurServiceAwareTrait;
use BjyAuthorize\Provider\Identity\ProviderInterface;
use Doctrine\ORM\NonUniqueResultException;
use UnicaenApp\Exception\RuntimeException;
use UnicaenAuth\Provider\Identity\ChainableProvider;
use UnicaenAuth\Provider\Identity\ChainEvent;
use Zend\Authentication\AuthenticationService;
@@ -159,16 +157,7 @@ class IdentityProvider implements ProviderInterface, ChainableProvider, ServiceL
     */
    private function getRolesFromDoctorant()
    {
        $id = $this->userWrapper->getSupannId();
        $domaineEtab = $this->userWrapper->getDomainFromEppn();
        $etablissement = $this->getEtablissementService()->getRepository()->findOneByDomaine($domaineEtab);
        $sourceCode = $etablissement->prependPrefixTo($id);

        try {
            $doctorant = $this->doctorantService->getRepository()->findOneBySourceCode($sourceCode);
        } catch (NonUniqueResultException $e) {
            throw new RuntimeException("Plusieurs doctorants ont été trouvés avec le même source code: " . $sourceCode);
        }
        $doctorant = $this->doctorantService->findOneByUserWrapper($this->userWrapper);

        if (! $doctorant) {
            return [];
+38
Changes for module/Application/src/Application/Service/Doctorant/DoctorantService.php: 38 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -5,10 +5,16 @@ namespace Application\Service\Doctorant;
use Application\Entity\Db\Doctorant;
use Application\Entity\Db\DoctorantCompl;
use Application\Entity\Db\Repository\DoctorantRepository;
use Application\Entity\UserWrapper;
use Application\Service\BaseService;
use Application\Service\Etablissement\EtablissementServiceAwareTrait;
use Doctrine\ORM\NonUniqueResultException;
use UnicaenApp\Exception\RuntimeException;

class DoctorantService extends BaseService
{
    use EtablissementServiceAwareTrait;

    /**
     * @return DoctorantRepository
     */
@@ -47,4 +53,36 @@ class DoctorantService extends BaseService

        return $complement;
    }

    /**
     * @param UserWrapper $user
     * @return Doctorant|null
     */
    public function findOneByUserWrapper(UserWrapper $user)
    {
        $id = $user->getSupannId();
        if (! $id) {
            throw new RuntimeException("Aucun id supann disponible.");
        }

        $domaineEtab = $user->getDomainFromEppn();
        if (! $domaineEtab) {
            return null;
        }

        $etablissement = $this->getEtablissementService()->getRepository()->findOneByDomaine($domaineEtab);
        if (! $etablissement) {
            throw new RuntimeException("Aucun établissement trouvé avec ce domaine: " . $domaineEtab);
        }

        $sourceCode = $etablissement->prependPrefixTo($id);

        try {
            $doctorant = $this->getRepository()->findOneBySourceCode($sourceCode);
        } catch (NonUniqueResultException $e) {
            throw new RuntimeException("Anomalie: plusieurs doctorants ont été trouvés avec le même source code: " . $sourceCode);
        }

        return $doctorant;
    }
}
 No newline at end of file
Loading