From a31713b0dfe712f55619e126c6a9fa6d10a5576b Mon Sep 17 00:00:00 2001 From: jusabatier Date: Tue, 4 Jul 2023 15:23:39 +0200 Subject: [PATCH] Suppression table pivot request / request_object --- .../model/request/InformationRequest.java | 13 +- .../model/request/ObjectRequest.java | 11 +- .../cadastrapp/model/request/UserRequest.java | 4 +- database/patch_db_2_2_0.sh | 120 ++++++++++++++++++ database/sql/tables/request_information.sql | 35 +---- database/sql/updates/2_2_0/_update_2_2_0.sql | 25 ++++ 6 files changed, 165 insertions(+), 43 deletions(-) create mode 100644 database/patch_db_2_2_0.sh create mode 100644 database/sql/updates/2_2_0/_update_2_2_0.sql diff --git a/cadastrapp/src/main/java/org/georchestra/cadastrapp/model/request/InformationRequest.java b/cadastrapp/src/main/java/org/georchestra/cadastrapp/model/request/InformationRequest.java index b973df81..63248598 100644 --- a/cadastrapp/src/main/java/org/georchestra/cadastrapp/model/request/InformationRequest.java +++ b/cadastrapp/src/main/java/org/georchestra/cadastrapp/model/request/InformationRequest.java @@ -4,15 +4,12 @@ import java.util.Date; import java.util.Set; -import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; -import javax.persistence.JoinTable; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.persistence.SequenceGenerator; @@ -35,8 +32,8 @@ public class InformationRequest implements Serializable{ private static final long serialVersionUID = 5439786730972374577L; @Id - @SequenceGenerator(name = "HibernateSequence", sequenceName = "hibernate_sequence", initialValue = 0, allocationSize = 1) - @GeneratedValue(generator = "HibernateSequence") + @SequenceGenerator(name = "RequestIdHibernateSequence", sequenceName = "hibernate_sequence", initialValue = 0, allocationSize = 1) + @GeneratedValue(generator = "RequestIdHibernateSequence") private long requestId; @ManyToOne(optional=false, fetch = FetchType.EAGER) @@ -46,11 +43,7 @@ public class InformationRequest implements Serializable{ @Column(name="requestdate") private Date requestDate; - @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER) - @JoinTable(name = "request_information_object_request", - joinColumns = {@JoinColumn(name = "request_information_requestid")}, - inverseJoinColumns = {@JoinColumn(name = "objectsrequest_objectid")} - ) + @OneToMany(mappedBy = "informationRequest") private Set objectsRequest; @Column(name="askby") diff --git a/cadastrapp/src/main/java/org/georchestra/cadastrapp/model/request/ObjectRequest.java b/cadastrapp/src/main/java/org/georchestra/cadastrapp/model/request/ObjectRequest.java index 6f4aee3e..1a0baf62 100644 --- a/cadastrapp/src/main/java/org/georchestra/cadastrapp/model/request/ObjectRequest.java +++ b/cadastrapp/src/main/java/org/georchestra/cadastrapp/model/request/ObjectRequest.java @@ -6,6 +6,8 @@ import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; import javax.persistence.SequenceGenerator; import javax.persistence.Table; import javax.xml.bind.annotation.XmlAttribute; @@ -22,10 +24,15 @@ public class ObjectRequest implements Serializable { private static final long serialVersionUID = 5439786730972374577L; @Id - @SequenceGenerator(name = "HibernateSequence", sequenceName = "hibernate_sequence", initialValue = 0, allocationSize = 1) - @GeneratedValue(generator = "HibernateSequence") + @SequenceGenerator(name = "ObjectIdHibernateSequence", sequenceName = "hibernate_sequence", initialValue = 0, allocationSize = 1) + @GeneratedValue(generator = "ObjectIdHibernateSequence") private long objectId; + @ManyToOne + @JoinColumn(name="request_information", referencedColumnName="requestid", nullable=false, updatable=false) + @Column(name = "requestid") + private InformationRequest informationRequest; + @Column(name = "type") // COMPTECOMMUNAL = 0; // PARCELLE_ID = 1; diff --git a/cadastrapp/src/main/java/org/georchestra/cadastrapp/model/request/UserRequest.java b/cadastrapp/src/main/java/org/georchestra/cadastrapp/model/request/UserRequest.java index b99803ce..992cdaa2 100644 --- a/cadastrapp/src/main/java/org/georchestra/cadastrapp/model/request/UserRequest.java +++ b/cadastrapp/src/main/java/org/georchestra/cadastrapp/model/request/UserRequest.java @@ -20,8 +20,8 @@ public class UserRequest implements Serializable { private static final long serialVersionUID = -9140660737315556020L; @Id - @SequenceGenerator(name = "HibernateSequence", sequenceName = "hibernate_sequence", initialValue = 0, allocationSize = 1) - @GeneratedValue(generator = "HibernateSequence") + @SequenceGenerator(name = "UserIdHibernateSequence", sequenceName = "hibernate_sequence", initialValue = 0, allocationSize = 1) + @GeneratedValue(generator = "UserIdHibernateSequence") @Column(name="userid") private long userId; diff --git a/database/patch_db_2_2_0.sh b/database/patch_db_2_2_0.sh new file mode 100644 index 00000000..7ef8fb32 --- /dev/null +++ b/database/patch_db_2_2_0.sh @@ -0,0 +1,120 @@ +#! /bin/bash + + +clear +git_version=$(git rev-parse HEAD) + +echo "---------------------------------------------------------------" +echo " Cadastrapp : script de mise à jour de la structure de données " +echo "---------------------------------------------------------------" +echo "" +echo " version : $git_version" +echo "" +echo "--------------------------------------------------------------" +echo " Lecture du fichier de configuration" +echo "--------------------------------------------------------------" +echo "" + +# lecture du fichier de configuration des connexions +. config.sh + +# verifie si le mode silencieux est activé +silentMode=False +while [[ "$#" -gt 0 ]] +do + case $1 in + -s|--silent) + silentMode=True + ;; + -*|--*) + echo "Invalid option: $1" + ;; + esac + shift +done + +if [ "$uniqueDB" = True ] ; then + echo " 1 seule base de données sera utilisée : $cadastrappDBName sur la machine $cadastrappDBHost" + echo " schéma des données cadastre QGIS : $qgisDBSchema" + echo " schéma des données cadastrapp : $cadastrappDBSchema" +elif [ "$uniqueDB" = False ] ; then + echo " 2 bases de données seront utilisées" + echo " host > db > schema" + echo " source QGIS : $qgisDBHost > $qgisDBName > $qgisDBSchema" + echo " cible cadastrapp : $cadastrappDBHost > $cadastrappDBName > $cadastrappDBSchema" +else + echo " pb de configuration : stop" + exit 1 +fi + +if [ "$orgsAutorisations" = True ] ; then + invalidLdapParam=False + if [ -z "$ldapUri" ] ; then + echo "Paramètre ldapUri manquant !" + invalidLdapParam=True + fi + + if [ -z "$ldapPath" ] ; then + echo "Paramètre ldapPath manquant !" + invalidLdapParam=True + fi + + if [ -z "$ldapBindDn" ] ; then + echo "Paramètre ldapBindDn manquant !" + invalidLdapParam=True + fi + + if [ -z "$ldapBindPwd" ] ; then + echo "Paramètre ldapBindPwd manquant !" + invalidLdapParam=True + fi + if [ "$invalidLdapParam" = True ] ; then + echo " pb de configuration : stop" + exit 1 + fi +fi + +if [ "$silentMode" = False ] ; then + echo "" + read -p " Si ces infos sont exactes : appuyer sur la touche [Entrée] sinon faire ctrl + C pour arrêter." + echo "" +fi + +# +# cette fonction permet de remplacer les infos de connection +# avant exécution +# +replaceAndLaunch (){ + + if [ -z "$1" ] || [ ! -e $1 ] ; then + echo "Le fichier SQL $1 n'existe pas." + exit 1 + else + echo " Exécution du fichier : $1" + fi + + cat $1 | sed "{ + s/#schema_cadastrapp/$cadastrappDBSchema/g + s/#user_cadastrapp/$cadastrappDBUser/g + s/#DBHost_qgis/$qgisDBHost/g + s/#DBPort_qgis/$qgisDBPort/g + s/#DBName_qgis/$qgisDBName/g + s/#DBSchema_qgis/$qgisDBSchema/g + s/#DBUser_qgis/$qgisDBUser/g + s/#DBpasswd_qgis/$qgisDBPassword/g + s|#ldap_uri|$ldapUri|g + s/#ldap_path/$ldapPath/g + s/#ldap_binddn/$ldapBindDn/g + s/#ldap_bindpwd/$ldapBindPwd/g + }" |\ + PGPASSWORD=$cadastrappDBPassword psql -h $cadastrappDBHost -p $cadastrappDBPort -d $cadastrappDBName -U $cadastrappDBUser + +} + +# on purge la BD cadastrapp existante +replaceAndLaunch sql/updates/2_2_0/_update_2_2_0.sql + +echo "" +echo "--------------------------------------------------------------" +echo " FIN " +echo "--------------------------------------------------------------" diff --git a/database/sql/tables/request_information.sql b/database/sql/tables/request_information.sql index bcaf917f..1264d75a 100644 --- a/database/sql/tables/request_information.sql +++ b/database/sql/tables/request_information.sql @@ -51,7 +51,7 @@ ALTER TABLE #schema_cadastrapp.request_information ALTER TABLE #schema_cadastrapp.request_information ADD CONSTRAINT foreingKeyUserId FOREIGN KEY (userid) REFERENCES #schema_cadastrapp.request_user_information (userid) MATCH SIMPLE - ON UPDATE NO ACTION ON DELETE NO ACTION; + ON UPDATE NO ACTION ON DELETE CASCADE; ALTER TABLE #schema_cadastrapp.request_information OWNER TO #user_cadastrapp; @@ -61,6 +61,7 @@ ALTER TABLE #schema_cadastrapp.request_information CREATE TABLE #schema_cadastrapp.object_request ( objectid bigint NOT NULL, + requestid bigint NOT NULL, type integer, comptecommunal character varying(255), parcelle character varying(255), @@ -76,36 +77,12 @@ ALTER TABLE #schema_cadastrapp.object_request ADD CONSTRAINT object_request_pkey PRIMARY KEY (objectid ); ALTER TABLE #schema_cadastrapp.object_request - OWNER TO #user_cadastrapp; - - - - -CREATE TABLE #schema_cadastrapp.request_information_object_request -( - request_information_requestid bigint NOT NULL, - objectsrequest_objectid bigint NOT NULL -); - -ALTER TABLE #schema_cadastrapp.request_information_object_request - ADD CONSTRAINT request_information_object_request_pkey PRIMARY KEY (request_information_requestid , objectsrequest_objectid ); - -ALTER TABLE #schema_cadastrapp.request_information_object_request - ADD CONSTRAINT foreingKeyRequestObjectRequestId FOREIGN KEY (request_information_requestid) + ADD CONSTRAINT foreingKeyRequestId FOREIGN KEY (requestid) REFERENCES #schema_cadastrapp.request_information (requestid) MATCH SIMPLE - ON UPDATE NO ACTION ON DELETE NO ACTION; - -ALTER TABLE #schema_cadastrapp.request_information_object_request - ADD CONSTRAINT foreingKeyRequestObjectRequestObjectId FOREIGN KEY (objectsrequest_objectid) - REFERENCES #schema_cadastrapp.object_request (objectid) MATCH SIMPLE - ON UPDATE NO ACTION ON DELETE NO ACTION; - - ALTER TABLE #schema_cadastrapp.request_information_object_request - ADD CONSTRAINT request_information_object_request_objectsrequest_objectid_key UNIQUE (objectsrequest_objectid ); - -ALTER TABLE #schema_cadastrapp.request_information_object_request - OWNER TO #user_cadastrapp; + ON UPDATE NO ACTION ON DELETE CASCADE; +ALTER TABLE #schema_cadastrapp.object_request + OWNER TO #user_cadastrapp; diff --git a/database/sql/updates/2_2_0/_update_2_2_0.sql b/database/sql/updates/2_2_0/_update_2_2_0.sql new file mode 100644 index 00000000..a523c397 --- /dev/null +++ b/database/sql/updates/2_2_0/_update_2_2_0.sql @@ -0,0 +1,25 @@ +ALTER TABLE #schema_cadastrapp.request_information + DROP CONSTRAINT foreingKeyUserId; + +ALTER TABLE #schema_cadastrapp.request_information + ADD CONSTRAINT foreingKeyUserId FOREIGN KEY (userid) + REFERENCES #schema_cadastrapp.request_user_information (userid) MATCH SIMPLE + ON UPDATE NO ACTION ON DELETE CASCADE; + +ALTER TABLE #schema_cadastrapp.object_request + ADD COLUMN requestid bigint; + +UPDATE #schema_cadastrapp.object_request + SET requestid = rior.request_information_requestid + FROM #schema_cadastrapp.request_information_object_request rior + WHERE rior.objectsrequest_objectid = object_request.objectid; + +ALTER TABLE #schema_cadastrapp.object_request + ADD CONSTRAINT foreingKeyRequestId FOREIGN KEY (requestid) + REFERENCES #schema_cadastrapp.request_information (requestid) MATCH SIMPLE + ON UPDATE NO ACTION ON DELETE CASCADE; + +ALTER TABLE #schema_cadastrapp.object_request + ALTER COLUMN requestid SET NOT NULL; + +DROP TABLE #schema_cadastrapp.request_information_object_request;