Subversion Repositories eFlore/Applications.coel

Rev

Rev 1417 | Rev 1610 | 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.collection;
883 jpm 2
 
1513 jpm 3
import java.util.Iterator;
4
import java.util.Map;
5
import java.util.Set;
6
 
935 jpm 7
import org.tela_botanica.client.modeles.aDonnee;
1513 jpm 8
import org.tela_botanica.client.modeles.personne.Personne;
935 jpm 9
import org.tela_botanica.client.modeles.publication.Publication;
1513 jpm 10
import org.tela_botanica.client.util.Debug;
935 jpm 11
 
1513 jpm 12
import com.extjs.gxt.ui.client.data.ModelData;
883 jpm 13
import com.google.gwt.json.client.JSONObject;
14
 
15
public class CollectionAPublication extends aDonnee {
16
 
17
	private static final long serialVersionUID = 1L;
18
 
19
	public static final String PREFIXE = "ccapu";
1513 jpm 20
	private boolean removePrefix = true;
883 jpm 21
	private Publication publicationLiee = null;
1173 jpm 22
	public static String[] champsObligatoires = {"ccapu_id_collection", "ccapu_id_publication"};
883 jpm 23
 
24
	public CollectionAPublication() {
25
		initialiser(new JSONObject());
26
	}
1513 jpm 27
 
28
	public CollectionAPublication(boolean removePrefix) {
29
		this.removePrefix = removePrefix;
30
		initialiser(new JSONObject());
31
	}
883 jpm 32
 
33
	public CollectionAPublication(JSONObject collectionAPublicationListe) {
34
		initialiser(collectionAPublicationListe);
35
	}
36
 
1513 jpm 37
	public CollectionAPublication(ModelData model, boolean removePrefix)
38
	{
39
		this.removePrefix = removePrefix;
40
 
41
		Map<String, Object> a = model.getProperties();
42
 
43
		Set<String> cles = a.keySet();
44
		Iterator<String> it = cles.iterator();
45
		while (it.hasNext()) {
46
			String cle = it.next();
47
			if (a.get(cle) != null) {
48
				String cleObjet = "";
49
				if (removePrefix) {
50
					cleObjet = cle.replaceFirst("^"+Publication.PREFIXE+"_", "");
51
					cleObjet = cle.replaceFirst("^"+Personne.PREFIXE+"_", "");
52
					cleObjet = cleObjet.replaceFirst("^"+PREFIXE+"_", "");
53
				}
54
				else {
55
					cleObjet = cle;
56
				}
57
				this.set(cleObjet, a.get(cle));
58
			}
59
		}
60
 
61
		setPublication(new Publication(model, removePrefix));
62
		this.set("_etat_", a.get("_etat_"));
63
	}
64
 
883 jpm 65
	@Override
66
	protected String getPrefixe() {
67
		return PREFIXE;
68
	}
69
 
1173 jpm 70
	protected String[] getChampsObligatoires()	{
71
		return champsObligatoires;
72
	}
73
 
883 jpm 74
	private void initialiser(JSONObject collectionAPublicationListe) {
75
		setPublication(new Publication(collectionAPublicationListe));
76
		initialiserChampsPourGrille();
77
		initialiserModele(collectionAPublicationListe);
78
	}
79
 
80
	// PUBLICATION
81
	public Publication getPublication() {
82
		return publicationLiee;
83
	}
84
	public void setPublication(Publication publication) {
85
		publicationLiee = publication;
86
		initialiserChampsPourGrille();
907 jpm 87
		if (publication != null) {
88
			setIdPublication(publication.getId());
89
		}
883 jpm 90
	}
91
 
92
	private void initialiserChampsPourGrille() {
1513 jpm 93
		if (removePrefix) {
94
			set("fmt_auteur", getPublication().getAuteur());
95
			set("titre", getPublication().getTitre());
96
			set("collection", getPublication().getCollection());
97
			set("_editeur_", "");
98
			set("_annee_", "");
99
			set("indication_nvt", getPublication().getIndicationNvt());
100
			set("fascicule", getPublication().getFascicule());
101
			set("truk_pages", getPublication().getPages());
102
			set("_etat_", "");
103
		} else {
104
			set(Publication.PREFIXE+"_fmt_auteur", getPublication().getAuteur());
105
			set(Publication.PREFIXE+"_titre", getPublication().getTitre());
106
			set(Publication.PREFIXE+"_collection", getPublication().getCollection());
107
			set("_editeur_", "");
108
			set("_annee_", "");
109
			set(Publication.PREFIXE+"_indication_nvt", getPublication().getIndicationNvt());
110
			set(Publication.PREFIXE+"_fascicule", getPublication().getFascicule());
111
			set(Publication.PREFIXE+"_truk_pages", getPublication().getPages());
112
			set("_etat_", "");
113
		}
883 jpm 114
	}
115
 
116
	// ID
117
	/** Génère un identifiant de CollectionAPersonne.
118
	 *
119
	 * C'est une concaténation des clés primaires de la table coel_collection_a_personne séparées par un tiret "-".
120
	 *
121
	 * @return identifiant unique d'une relation "collection à personne".
122
	 */
123
	public String getId() {
124
		String idCollection = getIdCollection();
125
		String idPublication = getIdPublication();
126
		if (idCollection.equals("") && idPublication.equals("")) {
127
			return null;
128
		} else {
129
			return (idCollection+"-"+idPublication);
130
		}
131
	}
132
 
133
	//+---------------------------------------------------------------------------------------------------------------+
134
	// CHAMPS PROVENANT de la TABLE COEL_COLLECTION_A_PERSONNE
135
 
136
	// ID COLLECTION
137
	public String getIdCollection() {
1513 jpm 138
		if (removePrefix) return renvoyerValeurCorrecte("id_collection");
139
		else return renvoyerValeurCorrecte(PREFIXE+"_id_collection");
883 jpm 140
	}
141
	public void setIdCollection(String idCollection) {
1513 jpm 142
		if (removePrefix) set("id_collection", idCollection);
143
		else set(PREFIXE+"_id_collection", idCollection);
883 jpm 144
	}
145
 
146
	// ID PUBLICATION
147
	public String getIdPublication() {
1513 jpm 148
		if (removePrefix) return renvoyerValeurCorrecte("id_publication");
149
		else return renvoyerValeurCorrecte(PREFIXE+"_id_publication");
883 jpm 150
	}
151
	public void setIdPublication(String ip) {
1513 jpm 152
		if (removePrefix) set("id_publication", ip);
153
		else set(PREFIXE+"_id_publication", ip);
883 jpm 154
	}
155
 
156
}