Subversion Repositories eFlore/Applications.coel

Rev

Rev 992 | Rev 1014 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
935 jpm 1
package org.tela_botanica.client.modeles.publication;
741 aurelien 2
 
3
import java.util.Iterator;
4
import java.util.Set;
5
 
935 jpm 6
import org.tela_botanica.client.modeles.aDonnee;
7
import org.tela_botanica.client.modeles.personne.Personne;
8
 
741 aurelien 9
import com.google.gwt.json.client.JSONObject;
10
 
11
public class PublicationAPersonne extends aDonnee {
12
 
13
	private static final long serialVersionUID = 7769105365939978129L;
748 jpm 14
 
751 jpm 15
	public static final String PREFIXE = "cpuap";
16
	public static final String ROLE_AUTEUR = "2360";
992 gduche 17
	//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";
19
 
775 jpm 20
	private Personne personneLiee = null;
992 gduche 21
	private Publication publicationLiee = null;
775 jpm 22
 
992 gduche 23
	public PublicationAPersonne() {
24
		new PublicationAPersonne(new JSONObject());
25
	}
901 jpm 26
 
741 aurelien 27
	public PublicationAPersonne(JSONObject pubAPersListe) {
775 jpm 28
		personneLiee = new Personne(pubAPersListe);
992 gduche 29
		publicationLiee = new Publication(pubAPersListe);
775 jpm 30
 
992 gduche 31
		System.out.println("publication liee : " + publicationLiee);
741 aurelien 32
		// l'objet JSON est une table de hachage
33
		Set<String> im = pubAPersListe.keySet();
34
 
35
		// Parcourt pour chaque clé
36
		for (Iterator<String> it = im.iterator(); it.hasNext();) {
37
			// Si elle est associée à une valeur, nous l'ajoutons
38
			String cle = it.next();
39
			// Suppression de l'abréviation du champ. Inutile dans le contexte d'un objet
748 jpm 40
			String cleObjet = cle.replaceFirst("^"+PREFIXE+"_", "");
41
			// Valeur vide par défaut
42
			String valeur = "";
741 aurelien 43
			if (pubAPersListe.get(cle).isString() != null) {
748 jpm 44
				valeur = pubAPersListe.get(cle).isString().stringValue();
45
				this.set(cleObjet, valeur);
741 aurelien 46
			} else {
748 jpm 47
				this.set(cleObjet, valeur);
741 aurelien 48
			}
49
		}
992 gduche 50
 
51
		initialiserChampsPourGrille();
741 aurelien 52
	}
53
 
992 gduche 54
 
55
	private void initialiserChampsPourGrille() {
56
		set("fmt_auteur", publicationLiee.getAuteur());
57
		set("titre", publicationLiee.getTitre());
58
		set("collection", publicationLiee.getCollection());
59
		set("_editeur_", "");
60
		set("_annee_", "");
61
		set("indication_nvt", publicationLiee.getIndicationNvt());
62
		set("fascicule", publicationLiee.getFascicule());
63
		set("truk_pages", publicationLiee.getPages());
64
		set("_etat_", "");
1004 gduche 65
		set("_role_", "");
992 gduche 66
	}
67
 
68
 
748 jpm 69
	@Override
70
	protected String getPrefixe() {
71
		return PREFIXE;
72
	}
73
 
775 jpm 74
	public Personne getPersonne() {
75
		return personneLiee;
748 jpm 76
	}
775 jpm 77
	public void setPersonne(Personne personne) {
78
		personneLiee = personne;
901 jpm 79
		if (personne != null) {
80
			setIdPersonne(personne.getId());
81
		}
741 aurelien 82
	}
83
 
901 jpm 84
	// ID
85
	public String getId() {
86
		String idPublication = getIdPublication();
87
		String idPersonne = getIdPersonne();
88
		String idRole = getIdRole();
89
		if (idPublication.equals("") && idPersonne.equals("") && idRole.equals("")) {
90
			return null;
91
		} else {
92
			return (idPublication+"-"+idPersonne+"-"+idRole);
93
		}
94
	}
95
 
96
	// ID PUBLICATION
97
	public String getIdPublication() {
98
		return renvoyerValeurCorrecte("id_publication");
99
	}
100
	public void setIdPublication(String id) {
101
		set("id_publication", id);
102
	}
103
 
992 gduche 104
	// PUBLICATION LIEE
105
	public Publication getPublicationLiee()	{
106
		return this.publicationLiee;
107
	}
108
 
109
	// LIER PUBLICATION
110
	public void setPublicationLiee(Publication publication)	{
111
		this.publicationLiee = publication;
112
		initialiserChampsPourGrille();
113
	}
114
 
1004 gduche 115
	// ROLE
116
	public String getRole() {
117
		String role = this.get("_role_");
118
		if (role != null)	{
119
			return role;
120
		} else 	{
121
			return "";
122
		}
123
	}
124
 
901 jpm 125
	// ID PERSONNE
126
	public String getIdPersonne() {
127
		return renvoyerValeurCorrecte("id_personne");
128
	}
129
	public void setIdPersonne(String id) {
130
		set("id_personne", id);
131
	}
132
 
133
	// ID RôLE
134
	public String getIdRole() {
135
		return renvoyerValeurCorrecte("id_role");
136
	}
137
	public void setIdRole(String id) {
138
		set("id_role", id);
139
	}
140
 
141
	// TYPE
142
	public String getType() {
143
		return renvoyerValeurCorrecte("ce_truk_type");
144
	}
145
	public void setType(String type) {
146
		set("ce_truk_type", type);
147
	}
148
	public void setFonction(String type, String valeur) {
149
		setChaineDenormaliseUnique("ce_truk_type", type, valeur);
150
	}
775 jpm 151
}