Subversion Repositories eFlore/Applications.coel

Rev

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

Rev Author Line No. Line
463 jp_milcent 1
package org.tela_botanica.client.modeles;
2
 
871 jpm 3
import org.tela_botanica.client.Mediateur;
463 jp_milcent 4
import org.tela_botanica.client.RegistreId;
5
import org.tela_botanica.client.http.JsonRestRequestBuilder;
6
import org.tela_botanica.client.http.JsonRestRequestCallback;
7
import org.tela_botanica.client.interfaces.Rafraichissable;
871 jpm 8
import org.tela_botanica.client.util.UtilDAO;
463 jp_milcent 9
 
10
import com.extjs.gxt.ui.client.Registry;
11
import com.google.gwt.core.client.GWT;
871 jpm 12
import com.google.gwt.http.client.URL;
463 jp_milcent 13
import com.google.gwt.json.client.JSONArray;
14
import com.google.gwt.json.client.JSONObject;
15
import com.google.gwt.json.client.JSONValue;
16
 
17
public class CollectionAsyncDao {
18
 
19
	public static final String SERVICE_NOM = "CoelCollection";
871 jpm 20
	private String utilisateurId = null;
21
	private Rafraichissable vueARafraichir = null;
463 jp_milcent 22
 
871 jpm 23
	public CollectionAsyncDao(Rafraichissable vueARafraichirCourrante) {
24
		vueARafraichir = vueARafraichirCourrante;
25
		utilisateurId = ((Mediateur) Registry.get(RegistreId.MEDIATEUR)).getUtilisateurId();
26
	}
27
 
28
	public void selectionner(final String projetId, final String collectionId) {
463 jp_milcent 29
		// Ajout des paramètres et données à selectionner dans l'URL
871 jpm 30
		String[] parametres = {projetId, collectionId};
31
		final JsonRestRequestBuilder rb = UtilDAO.construireRequete(SERVICE_NOM, parametres);
463 jp_milcent 32
		rb.envoyerRequete(null, new JsonRestRequestCallback() {
468 jp_milcent 33
			@Override
463 jp_milcent 34
			public void surReponse(JSONValue responseValue) {
35
				if (responseValue != null) {
36
					// Si la requête est un succès, reception d'un objet ou d'un tableau
37
					if (responseValue.isObject() != null) {
38
						final JSONObject reponse = responseValue.isObject();
39
						Collection collection = new Collection(reponse);
40
						CollectionBotanique collectionBotanique = new CollectionBotanique(reponse);
41
 
42
						Information info = new Information("selection_collection");
43
						info.setDonnee(0, collection);
44
						info.setDonnee(1, collectionBotanique);
45
						vueARafraichir.rafraichir(info);
46
					} else if (responseValue.isArray() != null) {
47
						final JSONArray reponse = responseValue.isArray();
48
						CollectionListe collections = new CollectionListe(reponse);
49
						vueARafraichir.rafraichir(collections);
50
					} else {
871 jpm 51
						GWT.log(rb.getUrl()+"\n\tLa réponse n'est pas un objet ou un talbeau JSON et vaut : "+responseValue.toString(), null);
463 jp_milcent 52
					}
53
				} else {
54
					// Dans le cas, où nous demandons toutes les institutions et qu'il n'y en a pas, nous retournons un objet vide
55
					if (collectionId == null) {
56
						CollectionListe collections = new CollectionListe(0);
57
						vueARafraichir.rafraichir(collections);
58
					}
59
				}
60
			}
61
		});
62
	}
643 jp_milcent 63
 
871 jpm 64
	public void ajouter(Collection collection) {
65
		String postDonneesEncodees = construirePost(null, collection);
66
 
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) {
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);
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
		});
85
	}
86
 
87
	public void modifier(Collection collection) {
88
		String postDonneesEncodees = construirePost(collection.getId(), collection);
643 jp_milcent 89
 
871 jpm 90
		String[] parametres = {collection.getId()};
91
		final JsonRestRequestBuilder rb = UtilDAO.construireRequetePost(SERVICE_NOM, parametres);
92
		rb.envoyerRequete(postDonneesEncodees, new JsonRestRequestCallback() {
643 jp_milcent 93
			@Override
871 jpm 94
			public void surReponse(JSONValue responseValue) {
643 jp_milcent 95
				// Si la requête est un succès, reception d'une chaine
871 jpm 96
				if (responseValue.isString() != null) {
97
					Information info = new Information("modif_collection");
98
					info.setMessage(responseValue.isString().stringValue());
99
					vueARafraichir.rafraichir(info);
643 jp_milcent 100
				} else {
871 jpm 101
					GWT.log(rb.getUrl()+"\n\tLa réponse n'est pas une chaine JSON.", null);
643 jp_milcent 102
				}
103
			}
104
		});
105
	}
871 jpm 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) {
113
				if (responseValue.isString() != null) {
114
					Information info = new Information("suppression_collection");
115
					info.setMessage(responseValue.isString().stringValue());
116
					vueARafraichir.rafraichir(info);
117
				} else {
118
					GWT.log(rb.getUrl()+"\n\tLa réponse n'est pas une chaine JSON.", null);
119
				}
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
 
201
		return postDonnees;
202
	}
463 jp_milcent 203
}