Subversion Repositories eFlore/Applications.coel

Rev

Rev 1417 | Rev 1513 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1417 Rev 1428
1
package org.tela_botanica.client.modeles.publication;
1
package org.tela_botanica.client.modeles.publication;
2
 
2
 
3
import java.util.Iterator;
3
import java.util.Iterator;
-
 
4
import java.util.Map;
4
import java.util.Set;
5
import java.util.Set;
5
 
6
 
6
import org.tela_botanica.client.modeles.aDonnee;
7
import org.tela_botanica.client.modeles.aDonnee;
7
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;
8
 
10
 
9
import com.google.gwt.json.client.JSONObject;
11
import com.google.gwt.json.client.JSONObject;
10
 
12
 
11
public class PublicationAPersonne extends aDonnee {
13
public class PublicationAPersonne extends aDonnee {
12
 
14
 
13
	private static final long serialVersionUID = 7769105365939978129L;
15
	private static final long serialVersionUID = 7769105365939978129L;
14
	
16
	
15
	public static final String PREFIXE = "cpuap";
17
	public static final String PREFIXE = "cpuap";
16
	public static final String ROLE_AUTEUR = "2360";
18
	public static final String ROLE_AUTEUR = "2360";
17
	//FIXME: insérer en base de données une valeur cohérente pour l'identifiant ci-dessous
19
	//FIXME: insérer en base de données une valeur cohérente pour l'identifiant ci-dessous
18
	public static final String ROLE_SUJET = "30762";
20
	public static final String ROLE_SUJET = "30762";
19
	
21
	
20
	private Personne personneLiee = null;
22
	private Personne personneLiee = null;
21
	private Publication publicationLiee = null;
23
	private Publication publicationLiee = null;
22
	public static String[] champsObligatoires = {"cpuap_id_personne", "cpuap_id_publication", "cpuap_id_role"};
24
	public static String[] champsObligatoires = {"cpuap_id_personne", "cpuap_id_publication", "cpuap_id_role"};
23
	
25
	
24
	public PublicationAPersonne() {
26
	public PublicationAPersonne() {
25
		new PublicationAPersonne(new JSONObject());
27
		new PublicationAPersonne(new JSONObject());
26
	}
28
	}
27
	
29
	
28
	public PublicationAPersonne(JSONObject pubAPersListe) {
30
	public PublicationAPersonne(JSONObject pubAPersListe) {
29
		personneLiee = new Personne(pubAPersListe);
31
		Personne personne = new Personne(pubAPersListe);
-
 
32
		setPersonne(personne);
30
		publicationLiee = new Publication(pubAPersListe);
33
		publicationLiee = new Publication(pubAPersListe);
31
		
34
		
32
		// l'objet JSON est une table de hachage
35
		// l'objet JSON est une table de hachage
33
		Set<String> im = pubAPersListe.keySet();
36
		Set<String> im = pubAPersListe.keySet();
34
 
37
 
35
		// Parcourt pour chaque clé
38
		// Parcourt pour chaque clé
36
		for (Iterator<String> it = im.iterator(); it.hasNext();) {
39
		for (Iterator<String> it = im.iterator(); it.hasNext();) {
37
			// Si elle est associée à une valeur, nous l'ajoutons
40
			// Si elle est associée à une valeur, nous l'ajoutons
38
			String cle = it.next();
41
			String cle = it.next();
39
			// Suppression de l'abréviation du champ. Inutile dans le contexte d'un objet
42
			// Suppression de l'abréviation du champ. Inutile dans le contexte d'un objet
40
			String cleObjet = cle.replaceFirst("^"+PREFIXE+"_", "");
43
			String cleObjet = cle.replaceFirst("^"+PREFIXE+"_", "");
41
			// Valeur vide par défaut
44
			// Valeur vide par défaut
42
			String valeur = "";
45
			String valeur = "";
43
			if (pubAPersListe.get(cle).isString() != null) {
46
			if (pubAPersListe.get(cle).isString() != null) {
44
				valeur = pubAPersListe.get(cle).isString().stringValue();
47
				valeur = pubAPersListe.get(cle).isString().stringValue();
45
				this.set(cleObjet, valeur);
48
				this.set(cleObjet, valeur);
46
			} else {
49
			} else {
47
				this.set(cleObjet, valeur);
50
				this.set(cleObjet, valeur);
48
			}
51
			}
49
		}
52
		}
50
		
53
		
51
		initialiserChampsPourGrille();
54
		initialiserChampsPourGrille();
52
	}
55
	}
53
	
56
	
54
	
57
	
55
	private void initialiserChampsPourGrille() {
58
	private void initialiserChampsPourGrille() {
56
		set("fmt_auteur", publicationLiee.getAuteur());
59
		set("fmt_auteur", publicationLiee.getAuteur());
57
		set("titre", publicationLiee.getTitre());
60
		set("titre", publicationLiee.getTitre());
58
		set("collection", publicationLiee.getCollection());
61
		set("collection", publicationLiee.getCollection());
59
		set("_editeur_", "");
62
		set("_editeur_", "");
60
		set("_annee_", "");
63
		set("_annee_", "");
61
		set("indication_nvt", publicationLiee.getIndicationNvt());
64
		set("indication_nvt", publicationLiee.getIndicationNvt());
62
		set("fascicule", publicationLiee.getFascicule());
65
		set("fascicule", publicationLiee.getFascicule());
63
		set("truk_pages", publicationLiee.getPages());
66
		set("truk_pages", publicationLiee.getPages());
64
		set("_etat_", "");
67
		set("_etat_", "");
65
		set("_role_", this.get("id_role"));
68
		set("_role_", this.get("id_role"));
66
	}
69
	}
67
	
70
	
68
	
71
	
69
	@Override
72
	@Override
70
	protected String getPrefixe() {
73
	protected String getPrefixe() {
71
		return PREFIXE;
74
		return PREFIXE;
72
	}
75
	}
73
 
76
 
74
	protected String[] getChampsObligatoires()	{
77
	protected String[] getChampsObligatoires()	{
75
		return champsObligatoires;
78
		return champsObligatoires;
76
	}
79
	}
77
	
80
	
78
	public Personne getPersonne() {
81
	public Personne getPersonne() {
79
		return personneLiee;
82
		return personneLiee;
80
	}
83
	}
81
	public void setPersonne(Personne personne) {
84
	public void setPersonne(Personne personne) {
82
		personneLiee = personne;
85
		personneLiee = personne;
83
		if (personne != null) {
86
		if (personne != null) {
84
			setIdPersonne(personne.getId());
87
			setIdPersonne(personne.getId());
85
		}
88
		}
-
 
89
		
-
 
90
		Map<String, Object> a = personne.getProperties();
-
 
91
 
-
 
92
		Set<String> cles = a.keySet();
-
 
93
		Iterator<String> it = cles.iterator();
-
 
94
		while (it.hasNext()) {
-
 
95
			String cle = it.next();			
-
 
96
			if (a.get(cle) != null) {
-
 
97
				String cleObjet = cle.replaceFirst("^"+Personne.PREFIXE+"_", "");
-
 
98
				this.set(cleObjet, a.get(cle));
-
 
99
			}
-
 
100
		}
86
	}
101
	}
87
	
102
	
88
	// ID
103
	// ID
89
	public String getId() {
104
	public String getId() {
90
		String idPublication = getIdPublication();
105
		String idPublication = getIdPublication();
91
		String idPersonne = getIdPersonne();
106
		String idPersonne = getIdPersonne();
92
		String idRole = getIdRole();
107
		String idRole = getIdRole();
93
		if (idPublication.equals("") && idPersonne.equals("") && idRole.equals("")) {
108
		if (idPublication.equals("") && idPersonne.equals("") && idRole.equals("")) {
94
			return null;
109
			return null;
95
		} else {
110
		} else {
96
			return (idPublication+"-"+idPersonne+"-"+idRole);
111
			return (idPublication+"-"+idPersonne+"-"+idRole);
97
		}
112
		}
98
	}
113
	}
99
	
114
	
100
	// ID PUBLICATION
115
	// ID PUBLICATION
101
	public String getIdPublication() {
116
	public String getIdPublication() {
102
		return renvoyerValeurCorrecte("id_publication");
117
		return renvoyerValeurCorrecte("id_publication");
103
	}
118
	}
104
	public void setIdPublication(String id) {
119
	public void setIdPublication(String id) {
105
		set("id_publication", id);
120
		set("id_publication", id);
106
	}
121
	}
107
	
122
	
108
	// PUBLICATION LIEE
123
	// PUBLICATION LIEE
109
	public Publication getPublicationLiee()	{
124
	public Publication getPublicationLiee()	{
110
		return this.publicationLiee;
125
		return this.publicationLiee;
111
	}
126
	}
112
	
127
	
113
	// LIER PUBLICATION
128
	// LIER PUBLICATION
114
	public void setPublicationLiee(Publication publication)	{
129
	public void setPublicationLiee(Publication publication)	{
115
		this.publicationLiee = publication;
130
		this.publicationLiee = publication;
116
		initialiserChampsPourGrille();
131
		initialiserChampsPourGrille();
117
	}
132
	}
118
	
133
	
119
	// ROLE
134
	// ROLE
120
	public String getRole() {
135
	public String getRole() {
121
		String role = this.get("_role_");
136
		String role = this.get("_role_");
122
		if (role != null)	{
137
		if (role != null)	{
123
			return role;
138
			return role;
124
		} else 	{
139
		} else 	{
125
			return "";
140
			return "";
126
		}
141
		}
127
	}
142
	}
128
	
143
	
129
	// ID PERSONNE
144
	// ID PERSONNE
130
	public String getIdPersonne() {
145
	public String getIdPersonne() {
131
		return renvoyerValeurCorrecte("id_personne");
146
		return renvoyerValeurCorrecte("id_personne");
132
	}
147
	}
133
	public void setIdPersonne(String id) {
148
	public void setIdPersonne(String id) {
134
		set("id_personne", id);
149
		set("id_personne", id);
135
	}
150
	}
136
	
151
	
137
	// ID RôLE
152
	// ID RôLE
138
	public String getIdRole() {
153
	public String getIdRole() {
139
		return renvoyerValeurCorrecte("id_role");
154
		return renvoyerValeurCorrecte("id_role");
140
	}
155
	}
141
	public void setIdRole(String id) {
156
	public void setIdRole(String id) {
142
		set("id_role", id);
157
		set("id_role", id);
143
	}
158
	}
144
		
159
		
145
	// TYPE
160
	// TYPE
146
	public String getType() {
161
	public String getType() {
147
		return renvoyerValeurCorrecte("ce_truk_type");
162
		return renvoyerValeurCorrecte("ce_truk_type");
148
	}
163
	}
149
	public void setType(String type) {
164
	public void setType(String type) {
150
		set("ce_truk_type", type);
165
		set("ce_truk_type", type);
151
	}
166
	}
152
	public void setFonction(String type, String valeur) {
167
	public void setFonction(String type, String valeur) {
153
		setChaineDenormaliseUnique("ce_truk_type", type, valeur);
168
		setChaineDenormaliseUnique("ce_truk_type", type, valeur);
154
	}
169
	}
-
 
170
	
-
 
171
	// ORDRE DES AUTEURS
-
 
172
	public String getOrdreAuteurs() {
-
 
173
		return renvoyerValeurCorrecte("ordre");
-
 
174
	}
-
 
175
	public void setOrdreAuteurs(String ordre) {
-
 
176
		if (ordre.matches("[0-9]+")) {
-
 
177
			this.set("ordre", ordre);
-
 
178
		}
-
 
179
	}
155
}
180
}
156
181