Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suppression table pivot request / request_object #719

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand All @@ -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<ObjectRequest> objectsRequest;

@Column(name="askby")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
120 changes: 120 additions & 0 deletions database/patch_db_2_2_0.sh
Original file line number Diff line number Diff line change
@@ -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 "--------------------------------------------------------------"
35 changes: 6 additions & 29 deletions database/sql/tables/request_information.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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),
Expand All @@ -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;



Expand Down
25 changes: 25 additions & 0 deletions database/sql/updates/2_2_0/_update_2_2_0.sql
Original file line number Diff line number Diff line change
@@ -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;