Subversion Repositories eFlore/Applications.coel

Rev

Rev 1468 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1468 Rev 1513
1
package org.tela_botanica.client.modeles.collection;
1
package org.tela_botanica.client.modeles.collection;
2
 
2
 
3
import java.util.Iterator;
3
import java.util.Iterator;
4
import java.util.Map;
4
import java.util.Map;
5
import java.util.Set;
5
import java.util.Set;
6
 
6
 
7
import org.tela_botanica.client.modeles.aDonnee;
7
import org.tela_botanica.client.modeles.aDonnee;
8
import org.tela_botanica.client.modeles.personne.Personne;
8
import org.tela_botanica.client.modeles.personne.Personne;
9
import org.tela_botanica.client.util.Debug;
9
import org.tela_botanica.client.util.Debug;
10
import org.tela_botanica.client.util.UtilString;
10
import org.tela_botanica.client.util.UtilString;
11
 
11
 
12
import com.extjs.gxt.ui.client.data.BaseModelData;
12
import com.extjs.gxt.ui.client.data.BaseModelData;
13
import com.extjs.gxt.ui.client.data.ModelData;
13
import com.extjs.gxt.ui.client.data.ModelData;
14
import com.google.gwt.json.client.JSONObject;
14
import com.google.gwt.json.client.JSONObject;
15
 
15
 
16
public class CollectionAPersonne extends aDonnee {
16
public class CollectionAPersonne extends aDonnee {
17
	
17
	
18
	private static final long serialVersionUID = 1L;
18
	private static final long serialVersionUID = 1L;
19
	
19
	
20
	public static final String PREFIXE = "ccap";
20
	public static final String PREFIXE = "ccap";
21
	private Personne personneLiee = null;
21
	private Personne personneLiee = null;
22
	public static String[] champsObligatoires = {"ccap_id_collection", "ccap_id_personne", "ccap_id_role"};
22
	public static String[] champsObligatoires = {"ccap_id_collection", "ccap_id_personne", "ccap_id_role"};
23
	
23
	
24
	public CollectionAPersonne() {
24
	public CollectionAPersonne() {
25
		initialiser(new JSONObject());
25
		initialiser(new JSONObject());
26
	}
26
	}
27
	
27
	
28
	public CollectionAPersonne(JSONObject collectionAPersonneListe) {
28
	public CollectionAPersonne(JSONObject collectionAPersonneListe) {
29
		initialiser(collectionAPersonneListe);
29
		initialiser(collectionAPersonneListe);
30
	}
30
	}
31
	
31
	
32
	public CollectionAPersonne(ModelData model)
32
	public CollectionAPersonne(ModelData model)
33
	{		
33
	{		
34
		Map<String, Object> a = model.getProperties();
34
		Map<String, Object> a = model.getProperties();
35
 
35
		
36
		Set<String> cles = a.keySet();
36
		Set<String> cles = a.keySet();
37
		Iterator<String> it = cles.iterator();
37
		Iterator<String> it = cles.iterator();
38
		while (it.hasNext()) {
38
		while (it.hasNext()) {
39
			String cle = it.next();
39
			String cle = it.next();
40
			if (a.get(cle) != null) {
40
			if (a.get(cle) != null) {
41
				String cleObjet = "";				
41
				String cleObjet = "";				
42
				cleObjet = cle.replaceFirst("^"+CollectionAPersonne.PREFIXE+"_", "");
42
				cleObjet = cle.replaceFirst("^"+CollectionAPersonne.PREFIXE+"_", "");
43
				cleObjet = cleObjet.replaceFirst("^"+Personne.PREFIXE+"_", "");
43
				cleObjet = cleObjet.replaceFirst("^"+Personne.PREFIXE+"_", "");
44
				this.set(cleObjet, a.get(cle));
44
				this.set(cleObjet, a.get(cle));
45
			}
45
			}
46
		}
46
		}
47
 
47
 
48
		setPersonne(new Personne(model));
48
		setPersonne(new Personne(model));
49
		this.set("_etat_", a.get("_etat_"));
49
		this.set("_etat_", a.get("_etat_"));
50
	}
50
	}
51
	
51
	
52
	@Override
52
	@Override
53
	protected String getPrefixe() {
53
	protected String getPrefixe() {
54
		return PREFIXE;
54
		return PREFIXE;
55
	}
55
	}
56
	
56
	
57
	protected String[] getChampsObligatoires()	{
57
	protected String[] getChampsObligatoires()	{
58
		return champsObligatoires;
58
		return champsObligatoires;
59
	}
59
	}
60
	
60
	
61
	private void initialiser(JSONObject collectionAPersonneListe) {
61
	private void initialiser(JSONObject collectionAPersonneListe) {
62
		setPersonne(new Personne(collectionAPersonneListe));
62
		setPersonne(new Personne(collectionAPersonneListe));
63
		initialiserModele(collectionAPersonneListe);
63
		initialiserModele(collectionAPersonneListe);
64
		initialiserChampsPourGrille();
64
		initialiserChampsPourGrille();
65
	}
65
	}
66
	
66
	
67
	// PERSONNE
67
	// PERSONNE
68
	public Personne getPersonne() {
68
	public Personne getPersonne() {
69
		return personneLiee;
69
		return personneLiee;
70
	}
70
	}
71
	public void setPersonne(Personne personne) {
71
	public void setPersonne(Personne personne) {
72
		personneLiee = personne;
72
		personneLiee = personne;
73
		initialiserChampsPourGrille();
73
		initialiserChampsPourGrille();
74
		if (personne != null) {
74
		if (personne != null) {
75
			if (personne.getId() != null && !UtilString.isEmpty(personne.getId())) setIdPersonne(personne.getId());
75
			if (personne.getId() != null && !UtilString.isEmpty(personne.getId())) setIdPersonne(personne.getId());
76
		}
76
		}
77
	}
77
	}
78
	
78
	
79
	public void setPersonnePourGrillePaginable(Personne personne) {
79
	public void setPersonnePourGrillePaginable(Personne personne) {
80
		personneLiee = personne;
80
		personneLiee = personne;
81
		initialiserChampsPourGrillePaginable();
81
		initialiserChampsPourGrillePaginable();
82
		if (personne != null) {
82
		if (personne != null) {
83
			if (personne.getId() != null && !UtilString.isEmpty(personne.getId())) setIdPersonne(personne.getId());
83
			if (personne.getId() != null && !UtilString.isEmpty(personne.getId())) setIdPersonne(personne.getId());
84
		}
84
		}
85
	}
85
	}
86
	
86
	
87
	private void initialiserChampsPourGrille() {
87
	private void initialiserChampsPourGrille() {
88
		set("_role_", getIdRole());
88
		set("_role_", getIdRole());
89
		set("fmt_nom_complet", getPersonne().getNomComplet());
89
		set("fmt_nom_complet", getPersonne().getNomComplet());
90
		set("nom", getPersonne().getNom());
90
		set("nom", getPersonne().getNom());
91
		set("prenom", getPersonne().getPrenom());
91
		set("prenom", getPersonne().getPrenom());
92
		set("naissance_date", getPersonne().getNaissanceDate());
92
		set("naissance_date", getPersonne().getNaissanceDate());
93
		set("naissance_lieu", getPersonne().getNaissanceLieu());
93
		set("naissance_lieu", getPersonne().getNaissanceLieu());
94
		set("_deces_", getPersonne().getDeces());
94
		set("_deces_", getPersonne().getDeces());
95
		set("deces_date", getPersonne().getDecesDate());
95
		set("deces_date", getPersonne().getDecesDate());
96
		set("deces_lieu", getPersonne().getDecesLieu());
96
		set("deces_lieu", getPersonne().getDecesLieu());
97
		set("_etat_", "");
97
		set("_etat_", "");
98
	}
98
	}
99
	
99
	
100
	public void initialiserChampsPourGrillePaginable() {
100
	public void initialiserChampsPourGrillePaginable() {
101
		set("ccap_id_role", getIdRole());
101
		set("ccap_id_role", getIdRole());
102
		set("_role_", getIdRole());
102
		set("_role_", getIdRole());
103
		set("cp_fmt_nom_complet", getPersonne().getNomComplet());
103
		set("cp_fmt_nom_complet", getPersonne().getNomComplet());
104
		set("cp_nom", getPersonne().getNom());
104
		set("cp_nom", getPersonne().getNom());
105
		set("cp_prenom", getPersonne().getPrenom());
105
		set("cp_prenom", getPersonne().getPrenom());
106
		set("cp_naissance_date", getPersonne().getNaissanceDate());
106
		set("cp_naissance_date", getPersonne().getNaissanceDate());
107
		set("cp_naissance_lieu", getPersonne().getNaissanceLieu());
107
		set("cp_naissance_lieu", getPersonne().getNaissanceLieu());
108
		set("_deces_", getPersonne().getDeces());
108
		set("_deces_", getPersonne().getDeces());
109
		set("cp_deces", getPersonne().getDeces());
109
		set("cp_deces", getPersonne().getDeces());
110
		set("cp_deces_date", getPersonne().getDecesDate());
110
		set("cp_deces_date", getPersonne().getDecesDate());
111
		set("cp_deces_lieu", getPersonne().getDecesLieu());
111
		set("cp_deces_lieu", getPersonne().getDecesLieu());
112
	}
112
	}
113
	
113
	
114
	// ID
114
	// ID
115
	/** Génère un identifiant de CollectionAPersonne.
115
	/** Génère un identifiant de CollectionAPersonne.
116
	 * 
116
	 * 
117
	 * C'est une concaténation des clés primaires de la table coel_collection_a_personne séparées par un tiret "-".
117
	 * C'est une concaténation des clés primaires de la table coel_collection_a_personne séparées par un tiret "-".
118
	 * 
118
	 * 
119
	 * @return identifiant unique d'une relation "collection à personne".
119
	 * @return identifiant unique d'une relation "collection à personne".
120
	 */
120
	 */
121
	public String getId() {
121
	public String getId() {
122
		String idCollection = getIdCollection();
122
		String idCollection = getIdCollection();
123
		String idPersonne = getIdPersonne();
123
		String idPersonne = getIdPersonne();
124
		String idRole = getIdRole();
124
		String idRole = getIdRole();
125
		if (idCollection.equals("") && idPersonne.equals("") && idRole.equals("")) {
125
		if (idCollection.equals("") && idPersonne.equals("") && idRole.equals("")) {
126
			return null;
126
			return null;
127
		} else {
127
		} else {
128
			return (idCollection+"-"+idPersonne+"-"+idRole);
128
			return (idCollection+"-"+idPersonne+"-"+idRole);
129
		}
129
		}
130
	}
130
	}
131
	
131
	
132
	//+---------------------------------------------------------------------------------------------------------------+
132
	//+---------------------------------------------------------------------------------------------------------------+
133
	// CHAMPS PROVENANT de la TABLE COEL_COLLECTION_A_PERSONNE
133
	// CHAMPS PROVENANT de la TABLE COEL_COLLECTION_A_PERSONNE
134
	
134
	
135
	// ID COLLECTION
135
	// ID COLLECTION
136
	public String getIdCollection() {
136
	public String getIdCollection() {
137
		return renvoyerValeurCorrecte("id_collection");
137
		return renvoyerValeurCorrecte("id_collection");
138
	}
138
	}
139
	public void setIdCollection(String idCollection) {
139
	public void setIdCollection(String idCollection) {
140
		set("id_collection", idCollection);
140
		set("id_collection", idCollection);
141
	}
141
	}
142
	
142
	
143
	// ID PERSONNE
143
	// ID PERSONNE
144
	public String getIdPersonne() {
144
	public String getIdPersonne() {
145
		return renvoyerValeurCorrecte("id_personne");
145
		return renvoyerValeurCorrecte("id_personne");
146
	}
146
	}
147
	public void setIdPersonne(String ip) {
147
	public void setIdPersonne(String ip) {
148
		set("id_personne", ip);
148
		set("id_personne", ip);
149
	}
149
	}
150
	
150
	
151
	// ID RôLE
151
	// ID RôLE
152
	public String getIdRole() {
152
	public String getIdRole() {
153
		String role = renvoyerValeurCorrecte("id_role");
153
		String role = renvoyerValeurCorrecte("id_role");
-
 
154
		return role;
-
 
155
		/*
154
		if (role != null && !UtilString.isEmpty(role)) return role;
156
		if (role != null && !UtilString.isEmpty(role)) return role;
155
		else return renvoyerValeurCorrecte("_role_");
157
		else return renvoyerValeurCorrecte("_role_");*/
156
	}
158
	}
157
	public void setIdRole(String ir) {
159
	public void setIdRole(String ir) {
158
		set("id_role", ir);
160
		set("id_role", ir);
159
	}
161
	}
160
			
162
			
161
}
163
}