Subversion Repositories eFlore/Applications.coel

Rev

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