Commit ec6e1d66 authored by Bertrand Gauthier's avatar Bertrand Gauthier Committed by Thomas Hamel
Browse files

Nouveau module HDR

parent 81eab463
Loading
Loading
Loading
Loading
+6 −2
Changes for composer.json: 6 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -47,7 +47,7 @@

        "unicaen/alerte": "^3.0",
        "unicaen/app": "^6.1.6",
        "unicaen/auth-token": "^7.0",
        "unicaen/auth-token": "^7.1",
        "unicaen/authentification": "^6.4",
        "unicaen/console": "^6.0",
        "unicaen/db-anonym": "^4.0",
@@ -69,6 +69,7 @@
    "prefer-stable": true,
    "autoload": {
        "psr-0": {
            "Acteur\\": "module/Acteur/src",
            "Admission\\": "module/Admission/src",
            "Application\\": "module/Application/src",
            "ComiteSuiviIndividuel\\": "module/ComiteSuiviIndividuel/src",
@@ -76,6 +77,8 @@
            "Doctorant\\": "module/Doctorant/src",
            "Fichier\\": "module/Fichier/src",
            "Formation\\": "module/Formation/src",
            "HDR\\": "module/HDR/src",
            "Candidat\\": "module/Candidat/src",
            "Import\\": "module/Import/src",
            "Indicateur\\": "module/Indicateur/src",
            "Individu\\": "module/Individu/src",
@@ -88,7 +91,8 @@
            "Structure\\": "module/Structure/src",
            "SygalApi\\": "vendor/unicaen/sygal-api/src",
            "These\\": "module/These/src",
            "UnicaenAvis\\": "module/UnicaenAvis/src"
            "UnicaenAvis\\": "module/UnicaenAvis/src",
            "Validation\\": "module/Validation/src"
        }
    },
    "autoload-dev": {
+4 −0
Changes for config/application.config.php: 4 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -65,6 +65,7 @@ return [

        'Horodatage',
        'Structure',
        'Acteur',
        'These',
        'Fichier',
        'Import',
@@ -86,6 +87,9 @@ return [
        'Substitution',
        'SygalApi',
        'SygalApiImpl',
        'Validation',
        'HDR',
        'Candidat'
    ],
    'module_listener_options' => [
        'config_glob_paths'    => [
+906 −0

File added.

Preview size limit exceeded, changes collapsed.

+175 −0
Changes for doc/release-notes/module_hdr/02_module_acteur.sql: 175 added lines, 0 removed lines.
Original line number Diff line number Diff line
alter table acteur rename to acteur_these;

alter table acteur_these add soutenance_membre_id bigint references soutenance_membre on delete set null ;
create index acteur_these_soutenance_membre_id_idx
    on acteur_these(soutenance_membre_id);
create index acteur_these_qualite_id_idx
    on acteur_these (qualite_id);
create index acteur_these_ed_id_idx
    on acteur_these (acteur_ecoledoct_id);
create index acteur_these_ur_id_idx
    on acteur_these (unite_rech_id);

alter table soutenance_membre rename column acteur_id to acteur_id_sav;

update acteur_these a
    set soutenance_membre_id = sm.id
    from soutenance_membre sm
    join soutenance_proposition sp on sm.proposition_id = sp.id and sp.histo_destruction is null
    join these t on sp.these_id = t.id and t.histo_destruction is null and etat_these <> 'A'
    where sm.acteur_id_sav = a.id and sm.histo_destruction is null;
/* verif :
select * from soutenance_membre sm
         left join acteur_these a on sm.id = a.soutenance_membre_id
         where sm.acteur_id_sav <> a.id;
*/

/***** traque des acteurs figurant plusieurs fois pour un même soutenance_membre :
    select acteur_id, count(sm.id)
        from soutenance_membre sm
            join soutenance_proposition sp on sm.proposition_id = sp.id and sp.histo_destruction is null
            join these t on sp.these_id = t.id and t.histo_destruction is null and etat_these <> 'A'
        where sm.histo_destruction is null
        group by acteur_id
        having count(sm.id) > 1;
******/

create sequence acteur_these_id_seq owned by acteur_these.id;
alter table acteur_these alter column id set default nextval('acteur_these_id_seq');


----------------------------------------- HDR -------------------------------------------------

create table acteur_hdr
(
    id                     bigint                                                       not null
        constraint acteur_hdr_pkey
            primary key,
    individu_id            bigint                                                       not null
        constraint acteur_hdr_indiv_fk
            references individu,
    hdr_id               bigint                                                       not null
        constraint acteur_hdr_hdr_fk
            references hdr,
    role_id                bigint                                                       not null
        constraint acteur_hdr_role_id_fk
            references role,
    source_code            varchar(64)                                                  not null,
    source_id              bigint                                                       not null
        constraint acteur_hdr_source_fk
            references source,
    histo_createur_id      bigint                                                       not null
        constraint acteur_hdr_hc_fk
            references utilisateur,
    histo_creation         timestamp default ('now'::text)::timestamp without time zone not null,
    histo_modificateur_id  bigint
        constraint acteur_hdr_hm_fk
            references utilisateur,
    histo_modification     timestamp,
    histo_destructeur_id   bigint
        constraint acteur_hdr_hd_fk
            references utilisateur,
    histo_destruction      timestamp,
    qualite_id             bigint
        constraint fk_qualite_id
            references soutenance_qualite,
    etablissement_id       bigint
        constraint acteur_hdr_etab_id_fk
            references etablissement,
    unite_rech_id          bigint
        constraint acteur_hdr_unite_rech_id_fk
            references unite_rech
            on delete set null,
    ecole_doct_id    bigint
        constraint acteur_hdr_ecole_doct_id_fk
            references ecole_doct,
    soutenance_membre_id   bigint
                                                                                        references soutenance_membre
                                                                                            on delete set null,
    exterieur              boolean   default false                                      not null,
    ordre                  smallint  default 1                                          not null
);

create index acteur_hdr_id_idx
    on acteur_hdr (hdr_id);
create index acteur_hdr_acteur_etab_id_idx
    on acteur_hdr (etablissement_id);
create index acteur_hdr_individu_id_idx
    on acteur_hdr (individu_id);
create index acteur_hdr_role_id_idx
    on acteur_hdr (role_id);
create index acteur_hdr_qualite_id_idx
    on acteur_hdr (qualite_id);
create index acteur_hdr_acteur_ed_id_idx
    on acteur_hdr (ecole_doct_id);
create index acteur_hdr_acteur_ur_id_idx
    on acteur_hdr (unite_rech_id);
create index acteur_hdr_soutenance_membre_id_idx
    on acteur_hdr (soutenance_membre_id);
create index acteur_hdr_histo_destruct_id_idx
    on acteur_hdr (histo_destructeur_id);
create index acteur_hdr_histo_modif_id_idx
    on acteur_hdr (histo_modificateur_id);
create unique index acteur_hdr_source_code_uniq
    on acteur_hdr (source_code);
create index acteur_hdr_source_id_idx
    on acteur_hdr (source_id);
create sequence acteur_hdr_id_seq owned by acteur_hdr.id;
alter table acteur_hdr alter column id set default nextval('acteur_hdr_id_seq');




create function hdr_rech_compute_haystack(eds_code character varying,
                                          urs_code character varying,
                                          d_source_code character varying,
                                          id_nom_patronymique character varying,
                                          id_nom_usuel character varying,
                                          id_prenom1 character varying,
                                          a_agg character varying) returns character varying
    language plpgsql
as
$$begin
    return btrim(str_reduce(
            'code-ed{' || COALESCE(eds_code, '') || '} ' ||
            'code-ur{' || COALESCE(urs_code, '') || '} ' ||
            'doctorant-numero{' || substr(d_source_code, "position"(d_source_code, '::') + 2) || '} ' ||
            'doctorant-nom{' || id_nom_patronymique || ' ' || id_nom_usuel || '} ' ||
            'doctorant-prenom{' || id_prenom1 || '} ' ||
            'directeur-nom{' || a_agg || '} '
                 ));
end;
$$;



create view hdr_rech as
WITH acteurs AS (
    SELECT a.hdr_id,
           string_agg(COALESCE(ia.nom_usuel::text, ''::text), ' '::text) AS agg
    FROM acteur_hdr a
             JOIN hdr t on a.hdr_id = t.id and t.histo_destruction is null
             JOIN role r ON a.role_id = r.id AND r.code in ('HDR_GARANT')
             JOIN individu ia ON ia.id = a.individu_id and ia.histo_destruction is null
    WHERE a.histo_destruction IS NULL
    GROUP BY 1
)
SELECT 'now'::text::timestamp without time zone AS date_creation,
       t.source_code AS code_hdr,
       d.source_code AS code_candidat,
       ed.source_code AS code_ecole_doct,
       hdr_rech_compute_haystack(eds.code,
                                 urs.code,
                                 d.source_code,
                                 id.nom_patronymique,
                                 id.nom_usuel,
                                 id.prenom1,
                                 a.agg::character varying) AS haystack
FROM hdr t
         JOIN candidat_hdr d ON d.id = t.candidat_id
         JOIN individu id ON id.id = d.individu_id
         LEFT JOIN ecole_doct ed ON t.ecole_doct_id = ed.id
         LEFT JOIN structure eds ON ed.structure_id = eds.id
         LEFT JOIN unite_rech ur ON t.unite_rech_id = ur.id
         LEFT JOIN structure urs ON ur.structure_id = urs.id
         LEFT JOIN acteurs a ON a.hdr_id = t.id;
 No newline at end of file
+140 −0
Changes for doc/release-notes/module_hdr/03_module_validation.sql: 140 added lines, 0 removed lines.
Original line number Diff line number Diff line
call unicaen_indicateur_delete_matviews();

----------------------------------------------- these ----------------------------------------------

alter table validation rename to validation_these;

alter index validation_hcfk_idx rename to validation_these_hcfk_idx;
alter index validation_hdfk_idx rename to validation_these_hdfk_idx;
alter index validation_hmfk_idx rename to validation_these_hmfk_idx;
alter index validation_type_idx rename to validation_these_type_idx;
alter index validation_individu_idx rename to validation_these_individu_idx;

alter table validation_these rename constraint validation_pkey to validation_these_pkey;
alter table validation_these rename constraint validation_individu_id_fk to validation_these_individu_id_fk;
alter table validation_these rename constraint validation_hcfk to validation_these_hcfk;
alter table validation_these rename constraint validation_hmfk to validation_these_hmfk;
alter table validation_these rename constraint validation_hdfk to validation_these_hdfk;

alter sequence validation_id_seq rename to validation_these_id_seq;

create table validation
(
    id                    bigint                                                       not null
        primary key,
    type_validation_id    bigint                                                       not null
        constraint validation_type_validation_fk
            references type_validation,
    histo_creation        timestamp default ('now'::text)::timestamp without time zone not null,
    histo_createur_id     bigint    default 1                                          not null
        constraint validation_hcfk
            references utilisateur,
    histo_modification    timestamp default ('now'::text)::timestamp without time zone not null,
    histo_modificateur_id bigint    default 1                                          not null
        constraint validation_hmfk
            references utilisateur,
    histo_destruction     timestamp,
    histo_destructeur_id  bigint
        constraint validation_hdfk
            references utilisateur
);

create index validation_hcfk_idx
    on validation (histo_createur_id);
create index validation_hdfk_idx
    on validation (histo_destructeur_id);
create index validation_hmfk_idx
    on validation (histo_modificateur_id);
create index validation_type_idx
    on validation (type_validation_id);

create sequence validation_id_seq owned by validation.id;
alter table validation alter column id set default nextval('validation_id_seq');

alter table validation_these add validation_id bigint constraint validation_these_validation_fk references validation;

create index validation_these_validation_idx on validation_these (validation_id);

create or replace procedure create_validations_from_validation_these() language plpgsql as
$$declare
    v validation_these;
begin
    for v in select * from validation_these loop
        insert into validation(id, type_validation_id, histo_creation, histo_createur_id, histo_modification, histo_modificateur_id, histo_destruction, histo_destructeur_id)
        values (v.id, v.type_validation_id, v.histo_creation, v.histo_createur_id, v.histo_modification, v.histo_modificateur_id, v.histo_destruction, v.histo_destructeur_id);
        update validation_these set validation_id = v.id where id = v.id;
    end loop;
    perform setval('validation_id_seq', coalesce(max(id),1)) from validation;
end;
$$;

call create_validations_from_validation_these();

alter table validation_these alter column validation_id set not null;


UPDATE indicateur SET requete = e'SELECT t.*
FROM THESE T
         LEFT JOIN VALIDATION_THESE VT ON T.ID = VT.THESE_ID
         LEFT JOIN VALIDATION V ON V.ID = VT.VALIDATION_ID
         LEFT JOIN TYPE_VALIDATION N on V.TYPE_VALIDATION_ID = N.ID
WHERE T.DATE_SOUTENANCE > (current_timestamp - interval \'2 months\')
  AND T.ETAT_THESE = \'E\'
  AND N.CODE = \'PAGE_DE_COUVERTURE\'
  AND VT.ID IS NULL;'
WHERE id = 2 and libelle = 'Pas de PDC à 2 mois';




----------------------------------------------- HDR ----------------------------------------------


create table public.validation_hdr
(
    id                    bigint                                                       not null
        constraint validation_hdr_pkey
            primary key,
    hdr_id              bigint                                                       not null
        constraint validation_hdr_fk
            references public.hdr,
    individu_id           bigint
        constraint validation_hdr_individu_id_fk
            references public.individu,
    histo_creation        timestamp default ('now'::text)::timestamp without time zone not null,
    histo_createur_id     bigint    default 1                                          not null
        constraint validation_hdr_hcfk
            references public.utilisateur,
    histo_modification    timestamp default ('now'::text)::timestamp without time zone not null,
    histo_modificateur_id bigint    default 1                                          not null
        constraint validation_hdr_hmfk
            references public.utilisateur,
    histo_destruction     timestamp,
    histo_destructeur_id  bigint
        constraint validation_hdr_hdfk
            references public.utilisateur,
    validation_id         bigint                                                       not null
        constraint validation_hdr_validation_fk
            references public.validation
);

create index validation_hdr_hcfk_idx
    on public.validation_hdr (histo_createur_id);
create index validation_hdr_hdfk_idx
    on public.validation_hdr (histo_destructeur_id);
create index validation_hdr_hmfk_idx
    on public.validation_hdr (histo_modificateur_id);
create index validation_hdr_individu_idx
    on public.validation_hdr (individu_id);
create index validation_hdr_idx
    on public.validation_hdr (hdr_id);
create index validation_hdr_validation_idx
    on public.validation_hdr (validation_id);


create sequence validation_hdr_id_seq owned by validation_hdr.id;
alter table validation_hdr alter column id set default nextval('validation_hdr_id_seq');


ALTER TABLE soutenance_avis ADD COLUMN validation_hdr_id bigint REFERENCES validation_hdr(id);
ALTER TABLE soutenance_avis RENAME COLUMN validation_id TO validation_these_id;
 No newline at end of file
Loading