Subversion Repositories eFlore/Applications.coel

Rev

Rev 743 | Rev 935 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 743 Rev 871
Line 1... Line 1...
1
package org.tela_botanica.client.modeles;
1
package org.tela_botanica.client.modeles;
Line -... Line 2...
-
 
2
 
2
 
3
import org.tela_botanica.client.Mediateur;
3
import org.tela_botanica.client.RegistreId;
4
import org.tela_botanica.client.RegistreId;
4
import org.tela_botanica.client.http.JsonRestRequestBuilder;
5
import org.tela_botanica.client.http.JsonRestRequestBuilder;
5
import org.tela_botanica.client.http.JsonRestRequestCallback;
6
import org.tela_botanica.client.http.JsonRestRequestCallback;
-
 
7
import org.tela_botanica.client.interfaces.Rafraichissable;
Line 6... Line 8...
6
import org.tela_botanica.client.interfaces.Rafraichissable;
8
import org.tela_botanica.client.util.UtilDAO;
7
 
9
 
8
import com.extjs.gxt.ui.client.Registry;
10
import com.extjs.gxt.ui.client.Registry;
9
import com.google.gwt.core.client.GWT;
11
import com.google.gwt.core.client.GWT;
10
import com.google.gwt.http.client.RequestBuilder;
12
import com.google.gwt.http.client.URL;
11
import com.google.gwt.json.client.JSONArray;
13
import com.google.gwt.json.client.JSONArray;
Line 12... Line 14...
12
import com.google.gwt.json.client.JSONObject;
14
import com.google.gwt.json.client.JSONObject;
Line 13... Line 15...
13
import com.google.gwt.json.client.JSONValue;
15
import com.google.gwt.json.client.JSONValue;
-
 
16
 
-
 
17
public class CollectionAsyncDao {
Line -... Line 18...
-
 
18
	
-
 
19
	public static final String SERVICE_NOM = "CoelCollection";
-
 
20
	private String utilisateurId = null;
-
 
21
	private Rafraichissable vueARafraichir = null;
-
 
22
	
14
 
23
	public CollectionAsyncDao(Rafraichissable vueARafraichirCourrante) {
15
public class CollectionAsyncDao {
24
		vueARafraichir = vueARafraichirCourrante;
16
	
-
 
17
	public static final String SERVICE_NOM = "CoelCollection";
-
 
18
	
-
 
19
	public void selectionner(final Rafraichissable vueARafraichir, final String projetId, final String collectionId) {
25
		utilisateurId = ((Mediateur) Registry.get(RegistreId.MEDIATEUR)).getUtilisateurId();
20
		// Ajout des paramètres et données à selectionner dans l'URL
-
 
21
		final String url = ((Configuration) Registry.get(RegistreId.CONFIG)).getServiceBaseUrl() + 
-
 
22
			SERVICE_NOM + "/" +
26
	}
23
			(projetId == null ? "*" : projetId) + "/" +
-
 
24
			(collectionId == null ? "*" : collectionId) + "/" +
27
	
25
			"";
28
	public void selectionner(final String projetId, final String collectionId) {
26
		
29
		// Ajout des paramètres et données à selectionner dans l'URL
27
		JsonRestRequestBuilder rb = new JsonRestRequestBuilder(RequestBuilder.GET, url);
30
		String[] parametres = {projetId, collectionId};
28
		
31
		final JsonRestRequestBuilder rb = UtilDAO.construireRequete(SERVICE_NOM, parametres);
Line 43... Line 46...
43
					} else if (responseValue.isArray() != null) {
46
					} else if (responseValue.isArray() != null) {
44
						final JSONArray reponse = responseValue.isArray();
47
						final JSONArray reponse = responseValue.isArray();
45
						CollectionListe collections = new CollectionListe(reponse);
48
						CollectionListe collections = new CollectionListe(reponse);
46
						vueARafraichir.rafraichir(collections);
49
						vueARafraichir.rafraichir(collections);
47
					} else {
50
					} else {
48
						GWT.log(url+"\n\tLa réponse n'est pas un objet ou un talbeau JSON et vaut : "+responseValue.toString(), null);
51
						GWT.log(rb.getUrl()+"\n\tLa réponse n'est pas un objet ou un talbeau JSON et vaut : "+responseValue.toString(), null);
49
					}
52
					}
50
				} else {
53
				} else {
51
					// Dans le cas, où nous demandons toutes les institutions et qu'il n'y en a pas, nous retournons un objet vide
54
					// Dans le cas, où nous demandons toutes les institutions et qu'il n'y en a pas, nous retournons un objet vide
52
					if (collectionId == null) {
55
					if (collectionId == null) {
53
						CollectionListe collections = new CollectionListe(0);
56
						CollectionListe collections = new CollectionListe(0);
Line 56... Line 59...
56
				}
59
				}
57
			}
60
			}
58
		});
61
		});
59
	}
62
	}
Line -... Line 63...
-
 
63
	
-
 
64
	public void ajouter(Collection collection) {
-
 
65
		String postDonneesEncodees = construirePost(null, collection);
60
	
66
 
61
	public void modifier(final Rafraichissable vueARafraichir, final String projetId, final String collectionId, Collection collection) {
67
		final JsonRestRequestBuilder rb = UtilDAO.construireRequetePost(SERVICE_NOM);	
-
 
68
		rb.envoyerRequete(postDonneesEncodees, new JsonRestRequestCallback() {
-
 
69
			@Override
-
 
70
			public void surReponse(JSONValue responseValue) {
-
 
71
				if (responseValue.isString() != null) {
62
		// Ajout des paramètres et données à selectionner dans l'URL
72
					Information info = new Information("ajout_collection");
-
 
73
					String structureIdOuMessage = responseValue.isString().stringValue();
-
 
74
					if (structureIdOuMessage.matches("^[0-9]+$")) {
-
 
75
						info.setDonnee(structureIdOuMessage);
-
 
76
					} else {
-
 
77
						info.setMessage(structureIdOuMessage);
63
		final String url = ((Configuration) Registry.get(RegistreId.CONFIG)).getServiceBaseUrl() + 
78
					}
-
 
79
					vueARafraichir.rafraichir(info);
-
 
80
				} else {
-
 
81
					GWT.log(rb.getUrl()+"\n\tLa réponse n'est pas une chaine JSON.", null);
-
 
82
				}
-
 
83
			}
-
 
84
		});
64
			SERVICE_NOM + "/" + collectionId;
85
	}
-
 
86
	
65
		
87
	public void modifier(Collection collection) {
Line -... Line 88...
-
 
88
		String postDonneesEncodees = construirePost(collection.getId(), collection);
-
 
89
		
66
		JsonRestRequestBuilder rb = new JsonRestRequestBuilder(RequestBuilder.POST, url);
90
		String[] parametres = {collection.getId()};
67
		
91
		final JsonRestRequestBuilder rb = UtilDAO.construireRequetePost(SERVICE_NOM, parametres);
68
		rb.envoyerRequete(null, new JsonRestRequestCallback() {
92
		rb.envoyerRequete(postDonneesEncodees, new JsonRestRequestCallback() {
69
			@Override
-
 
70
			public void surReponse(JSONValue reponseValeur) {
-
 
71
				Information info = new Information("modif_collection");
93
			@Override
72
				
94
			public void surReponse(JSONValue responseValue) {
-
 
95
				// Si la requête est un succès, reception d'une chaine
-
 
96
				if (responseValue.isString() != null) {
-
 
97
					Information info = new Information("modif_collection");
-
 
98
					info.setMessage(responseValue.isString().stringValue());
-
 
99
					vueARafraichir.rafraichir(info);
-
 
100
				} else {
-
 
101
					GWT.log(rb.getUrl()+"\n\tLa réponse n'est pas une chaine JSON.", null);
-
 
102
				}
-
 
103
			}
-
 
104
		});
-
 
105
	}
-
 
106
	
-
 
107
	public void supprimer(String collectionsId) {
-
 
108
		String[] parametres = {utilisateurId, collectionsId};
-
 
109
		final JsonRestRequestBuilder rb = UtilDAO.construireRequetePost(SERVICE_NOM, parametres);
-
 
110
		rb.envoyerRequeteSuppression(new JsonRestRequestCallback() {
-
 
111
			@Override
-
 
112
			public void surReponse(JSONValue responseValue) {
73
				// Si la requête est un succès, reception d'une chaine
113
				if (responseValue.isString() != null) {
-
 
114
					Information info = new Information("suppression_collection");
74
				if (reponseValeur.isString() != null) {
115
					info.setMessage(responseValue.isString().stringValue());
75
					info.setMessage(reponseValeur.isString().stringValue());
116
					vueARafraichir.rafraichir(info);
76
				} else {
117
				} else {
77
					info.setDeboguage("La réponse n'est pas une chaine JSON.");
-
 
78
				}
-
 
79
				
118
					GWT.log(rb.getUrl()+"\n\tLa réponse n'est pas une chaine JSON.", null);
80
				vueARafraichir.rafraichir(info);
119
				}
81
			}
120
			}
-
 
121
		});
-
 
122
	}
-
 
123
	
-
 
124
	private String construirePost(String collectionId, Collection collection) {
-
 
125
		String postDonnees = "cmhl_ce_modifier_par=" + URL.encodeComponent(utilisateurId); 
-
 
126
			
-
 
127
		if (collection != null) {
-
 
128
			if (collectionId != null) {
-
 
129
				postDonnees += "&cc_id_collection=" + URL.encodeComponent(collectionId);
-
 
130
			}
-
 
131
			postDonnees += "&cpr_abreviation=" + URL.encodeComponent(((ProjetListe) Registry.get(RegistreId.PROJETS)).get(collection.getIdProjet()).getAbreviation());
-
 
132
			postDonnees += "&cc_ce_projet=" + URL.encodeComponent(collection.getIdProjet()) +
-
 
133
				"&cc_ce_mere=" + URL.encodeComponent(collection.getCollectionMereId()) +
-
 
134
				"&cc_ce_structure=" + URL.encodeComponent(collection.getIdStructure()) +
-
 
135
				"&cc_truk_identifiant_alternatif=" + URL.encodeComponent(collection.getIdAlternatif()) +
-
 
136
				"&cc_truk_code=" + URL.encodeComponent(collection.getCode()) +
-
 
137
				"&cc_nom=" + URL.encodeComponent(collection.getNom()) +
-
 
138
				"&cc_truk_nom_alternatif=" + URL.encodeComponent(collection.getNomAlternatif()) +
-
 
139
				"&cc_description=" + URL.encodeComponent(collection.getDescription()) +
-
 
140
				"&cc_description_specialiste=" + URL.encodeComponent(collection.getDescriptionSpecialiste()) +
-
 
141
				"&cc_historique=" + URL.encodeComponent(collection.getHistorique()) +
-
 
142
				"&cc_truk_url=" + URL.encodeComponent(collection.getUrls()) +
-
 
143
				"&cc_truk_groupement_principe=" + URL.encodeComponent(collection.getGroupementPrincipe()) +
-
 
144
				"&cc_truk_groupement_but=" + URL.encodeComponent(collection.getGroupementBut()) +
-
 
145
				"&cc_ce_type=" + URL.encodeComponent(collection.getTypeNcd()) +
-
 
146
				"&cc_ce_type_depot=" + URL.encodeComponent(collection.getTypeDepot()) +
-
 
147
				"&cc_cote=" + URL.encodeComponent(collection.getCote()) +
-
 
148
				"&cc_truk_couverture_lieu=" + URL.encodeComponent(collection.getCouvertureLieu()) +
-
 
149
				"&cc_ce_specimen_type=" + URL.encodeComponent(collection.getSpecimenType()) +
-
 
150
				"&cc_specimen_type_nbre=" + URL.encodeComponent(collection.getSpecimenTypeNbre()) +
-
 
151
				"&cc_ce_specimen_type_nbre_precision=" + URL.encodeComponent(collection.getSpecimenTypeNbrePrecision()) +
-
 
152
				"&cc_ce_specimen_type_classement=" + URL.encodeComponent(collection.getSpecimenTypeClassement());
-
 
153
		}
-
 
154
		
-
 
155
		if (collection.getBotanique() != null) {
-
 
156
			CollectionBotanique collectionBotanique = collection.getBotanique();
-
 
157
			postDonnees += "&ccb_nbre_echantillon=" + URL.encodeComponent(collectionBotanique.getNbreEchantillon()) +
-
 
158
				"&ccb_ce_truk_type=" + URL.encodeComponent(collectionBotanique.getType()) +
-
 
159
				"&ccb_truk_unite_rangement=" + URL.encodeComponent(collectionBotanique.getUniteRangement()) +
-
 
160
				"&ccb_ce_unite_rangement_etat=" + URL.encodeComponent(collectionBotanique.getUniteRangementEtat()) +
-
 
161
				"&ccb_truk_unite_base=" + URL.encodeComponent(collectionBotanique.getUniteBase()) +
-
 
162
				"&ccb_truk_conservation_papier_type=" + URL.encodeComponent(collectionBotanique.getConservationPapierType()) +
-
 
163
				"&ccb_truk_conservation_methode=" + URL.encodeComponent(collectionBotanique.getConservationMethode()) +
-
 
164
				"&ccb_specimen_fixation_pourcent=" + URL.encodeComponent(collectionBotanique.getSpecimenFixationPourcent()) +
-
 
165
				"&ccb_etiquette_fixation_pourcent=" + URL.encodeComponent(collectionBotanique.getEtiquetteFixationPourcent()) +
-
 
166
				"&ccb_truk_specimen_fixation_methode=" + URL.encodeComponent(collectionBotanique.getSpecimenFixationMethode()) +
-
 
167
				"&ccb_truk_etiquette_fixation_support=" + URL.encodeComponent(collectionBotanique.getEtiquetteFixationSupport()) +
-
 
168
				"&ccb_truk_etiquette_fixation_specimen=" + URL.encodeComponent(collectionBotanique.getEtiquetteFixationSpecimen()) +
-
 
169
				"&ccb_truk_etiquette_ecriture=" + URL.encodeComponent(collectionBotanique.getEtiquetteEcriture()) +
-
 
170
				"&ccb_ce_traitement=" + URL.encodeComponent(collectionBotanique.getTraitement()) +
-
 
171
				"&ccb_truk_traitement_poison=" + URL.encodeComponent(collectionBotanique.getTraitementPoison()) +
-
 
172
				"&ccb_truk_traitement_insecte=" + URL.encodeComponent(collectionBotanique.getTraitementInsecte()) +
-
 
173
				"&ccb_ce_etat_general=" + URL.encodeComponent(collectionBotanique.getEtatGeneral()) +
-
 
174
				"&ccb_truk_degradation_specimen=" + URL.encodeComponent(collectionBotanique.getDegradationSpecimen()) +
-
 
175
				"&ccb_truk_degradation_presentation=" + URL.encodeComponent(collectionBotanique.getDegradationPresentation()) +
-
 
176
				"&ccb_ce_determination=" + URL.encodeComponent(collectionBotanique.getDetermination()) +
-
 
177
				"&ccb_truk_nature=" + URL.encodeComponent(collectionBotanique.getNature()) +
-
 
178
				"&ccb_specialite=" + URL.encodeComponent(collectionBotanique.getSpecialite()) +
-
 
179
				"&ccb_recolte_date_debut=" + URL.encodeComponent(collectionBotanique.getRecolteDateDebut()) +
-
 
180
				"&ccb_ce_recolte_date_debut_type=" + URL.encodeComponent(collectionBotanique.getRecolteDateDebutType()) +
-
 
181
				"&ccb_recolte_date_fin=" + URL.encodeComponent(collectionBotanique.getRecolteDateFin()) +
-
 
182
				"&ccb_ce_recolte_date_fin_type=" + URL.encodeComponent(collectionBotanique.getRecolteDateFinType()) +
-
 
183
				"&ccb_annotation_classement=" + URL.encodeComponent(collectionBotanique.getClassementAnnotation()) +
-
 
184
				"&ccb_ce_classement_etat=" + URL.encodeComponent(collectionBotanique.getClassementEtat()) +
-
 
185
				"&ccb_truk_etiquette_renseignement=" + URL.encodeComponent(collectionBotanique.getEtiquetteRenseignement()) +
-
 
186
				"&ccb_ce_precision_localite=" + URL.encodeComponent(collectionBotanique.getPrecisionLocalite()) +
-
 
187
				"&ccb_ce_precision_date=" + URL.encodeComponent(collectionBotanique.getPrecisionDate()) +
-
 
188
				"&ccb_annotation_diverse=" + URL.encodeComponent(collectionBotanique.getAnnotationsDiverses()) +
-
 
189
				"&ccb_ce_collection_integre=" + URL.encodeComponent(collectionBotanique.getCollectionIntegre()) +
-
 
190
				"&ccb_ce_collection_integre_info=" + URL.encodeComponent(collectionBotanique.getCollectionIntegreInfo()) +
-
 
191
				"&ccb_ce_inventaire=" + URL.encodeComponent(collectionBotanique.getInventaire()) +
-
 
192
				"&ccb_ce_inventaire_auteur=" + URL.encodeComponent(collectionBotanique.getInventaireAuteur()) +
-
 
193
				"&ccb_ce_inventaire_forme=" + URL.encodeComponent(collectionBotanique.getInventaireForme()) +
-
 
194
				"&ccb_inventaire_info=" + URL.encodeComponent(collectionBotanique.getInventaireInfo()) +
-
 
195
				"&ccb_ce_truk_inventaire_digital=" + URL.encodeComponent(collectionBotanique.getInventaireDigital()) +
-
 
196
				"&ccb_inventaire_digital_pourcent=" + URL.encodeComponent(collectionBotanique.getInventaireDigitalPourcent()) +
-
 
197
				"&ccb_ce_inventaire_etat=" + URL.encodeComponent(collectionBotanique.getInventaireEtat()) +
-
 
198
				"&ccb_inventaire_donnee_type=" + URL.encodeComponent(collectionBotanique.getInventaireDonneesTypes());
-
 
199
		}
-
 
200
		
82
		});
201
		return postDonnees;
83
	}
202
	}