Subversion Repositories eFlore/Applications.coel

Rev

Rev 935 | Rev 1004 | 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_", "");
65
	}
66
 
67
 
748 jpm 68
	@Override
69
	protected String getPrefixe() {
70
		return PREFIXE;
71
	}
72
 
775 jpm 73
	public Personne getPersonne() {
74
		return personneLiee;
748 jpm 75
	}
775 jpm 76
	public void setPersonne(Personne personne) {
77
		personneLiee = personne;
901 jpm 78
		if (personne != null) {
79
			setIdPersonne(personne.getId());
80
		}
741 aurelien 81
	}
82
 
901 jpm 83
	// ID
84
	public String getId() {
85
		String idPublication = getIdPublication();
86
		String idPersonne = getIdPersonne();
87
		String idRole = getIdRole();
88
		if (idPublication.equals("") && idPersonne.equals("") && idRole.equals("")) {
89
			return null;
90
		} else {
91
			return (idPublication+"-"+idPersonne+"-"+idRole);
92
		}
93
	}
94
 
95
	// ID PUBLICATION
96
	public String getIdPublication() {
97
		return renvoyerValeurCorrecte("id_publication");
98
	}
99
	public void setIdPublication(String id) {
100
		set("id_publication", id);
101
	}
102
 
992 gduche 103
	// PUBLICATION LIEE
104
	public Publication getPublicationLiee()	{
105
		return this.publicationLiee;
106
	}
107
 
108
	// LIER PUBLICATION
109
	public void setPublicationLiee(Publication publication)	{
110
		this.publicationLiee = publication;
111
		initialiserChampsPourGrille();
112
	}
113
 
901 jpm 114
	// ID PERSONNE
115
	public String getIdPersonne() {
116
		return renvoyerValeurCorrecte("id_personne");
117
	}
118
	public void setIdPersonne(String id) {
119
		set("id_personne", id);
120
	}
121
 
122
	// ID RôLE
123
	public String getIdRole() {
124
		return renvoyerValeurCorrecte("id_role");
125
	}
126
	public void setIdRole(String id) {
127
		set("id_role", id);
128
	}
129
 
130
	// TYPE
131
	public String getType() {
132
		return renvoyerValeurCorrecte("ce_truk_type");
133
	}
134
	public void setType(String type) {
135
		set("ce_truk_type", type);
136
	}
137
	public void setFonction(String type, String valeur) {
138
		setChaineDenormaliseUnique("ce_truk_type", type, valeur);
139
	}
775 jpm 140
}