Subversion Repositories eFlore/Applications.cel

Rev

Rev 32 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 32 Rev 44
1
package org.tela_botanica.client.modeles;
1
package org.tela_botanica.client.modeles;
2
 
2
 
3
import org.tela_botanica.client.Util;
3
import org.tela_botanica.client.Util;
4
import org.tela_botanica.client.interfaces.Rafraichissable;
4
import org.tela_botanica.client.interfaces.Rafraichissable;
5
import org.tela_botanica.client.observation.ObservationModele;
5
import org.tela_botanica.client.observation.ObservationModele;
6
 
6
 
7
import com.google.gwt.http.client.Request;
7
import com.google.gwt.http.client.Request;
8
import com.google.gwt.http.client.RequestBuilder;
8
import com.google.gwt.http.client.RequestBuilder;
9
import com.google.gwt.http.client.RequestCallback;
9
import com.google.gwt.http.client.RequestCallback;
10
import com.google.gwt.http.client.RequestException;
10
import com.google.gwt.http.client.RequestException;
11
import com.google.gwt.http.client.Response;
11
import com.google.gwt.http.client.Response;
12
import com.google.gwt.json.client.JSONArray;
12
import com.google.gwt.json.client.JSONArray;
13
import com.google.gwt.json.client.JSONParser;
13
import com.google.gwt.json.client.JSONParser;
14
import com.google.gwt.json.client.JSONString;
14
import com.google.gwt.json.client.JSONString;
15
import com.google.gwt.json.client.JSONValue;
15
import com.google.gwt.json.client.JSONValue;
16
import com.google.gwt.user.client.HTTPRequest;
-
 
17
import com.google.gwt.user.client.ResponseTextHandler;
-
 
18
 
16
 
19
/**
17
/**
20
 * DAO la liste des observations attachées a un observateur
18
 * DAO la liste des observations attachées a un observateur
21
 * @author David Delon
19
 * @author David Delon
22
 * TODO : se servir de ObservationDAO pour la lecture unitaire
20
 * TODO : se servir de ObservationDAO pour la lecture unitaire
23
 *
21
 *
24
 */
22
 */
25
public class ListeObservationAsynchroneDAO {
23
public class ListeObservationAsynchroneDAO {
26
 
24
 
27
	
25
	
28
	
26
	
29
	
27
	
30
	/**
28
	/**
31
	 * Le modèle associé au DAO
29
	 * Le modèle associé au DAO
32
	 */
30
	 */
33
	private ObservationModele observationModele = null ;
31
	private ObservationModele observationModele = null ;
34
	
32
	
35
	public ListeObservationAsynchroneDAO(ObservationModele observationModele)
33
	public ListeObservationAsynchroneDAO(ObservationModele observationModele)
36
	{
34
	{
37
	
35
	
38
		this.observationModele=observationModele;
36
		this.observationModele=observationModele;
39
	}
37
	}
40
	
38
	
41
	
39
	
42
	/**
40
	/**
43
	 * Envoie une requete au serveur jrest pour obtenir le nombre d'observation correspondant
41
	 * Envoie une requete au serveur jrest pour obtenir le nombre d'observation correspondant
44
	 * à des critères données en paramètres
42
	 * à des critères données en paramètres
45
	 * @param r le rafraichissable qui demande la mise à jour
43
	 * @param r le rafraichissable qui demande la mise à jour
46
	 * @param criteres un tableau nom/valeur des critères pour les observations
44
	 * @param criteres un tableau nom/valeur des critères pour les observations
47
	 */
45
	 */
48
	public void obtenirListeObservation(final Rafraichissable r, String utilisateur, String[][] criteres)
46
	public void obtenirListeObservation(final Rafraichissable r, String utilisateur, String[][] criteres)
49
	{
47
	{
50
		
48
		
51
		
49
		
52
		String requete = "" ;
50
		String requete = "" ;
53
			
51
			
54
		if(criteres != null)
52
		if(criteres != null)
55
		{
53
		{
56
			// on construit les paramètres du get avec les critères (&critere1=valeur1&critere2=valeur2 etc...)
54
			// on construit les paramètres du get avec les critères (&critere1=valeur1&critere2=valeur2 etc...)
57
			// ils contiennent limite et taille page
55
			// ils contiennent limite et taille page
58
			
56
			
59
			for (int i = 0; i < criteres.length; i++) {
57
			for (int i = 0; i < criteres.length; i++) {
60
				
58
				
61
				if(!criteres[i][1].equals(""))
59
				if(!criteres[i][1].equals(""))
62
				{
60
				{
63
					if(i!= 0)
61
					if(i!= 0)
64
					{
62
					{
65
						requete += "&";
63
						requete += "&";
66
					}
64
					}
67
					requete += criteres[i][0]+"="+criteres[i][1] ;
65
					requete += criteres[i][0]+"="+criteres[i][1] ;
68
				}
66
				}
69
			}
67
			}
70
		}	
68
		}	
71
		
69
		
72
		// on envoie le get asynchrone
70
		// on envoie le get asynchrone
73
		RequestBuilder rb = new RequestBuilder(RequestBuilder.GET,observationModele.getConfig().getServiceBaseUrl()
71
		RequestBuilder rb = new RequestBuilder(RequestBuilder.GET,observationModele.getConfig().getServiceBaseUrl()
74
				+"/InventoryObservationList/"+utilisateur+"/"+requete) ;
72
				+"/InventoryObservationList/"+utilisateur+"/"+requete) ;
75
		
73
		
76
		try {
74
		try {
77
			rb.sendRequest(null, new RequestCallback() {
75
			rb.sendRequest(null, new RequestCallback() {
78
 
76
 
79
				public void onError(Request request, Throwable exception) {
77
				public void onError(Request request, Throwable exception) {
80
					// TODO Auto-generated method stub
78
					// TODO Auto-generated method stub
81
					
79
					
82
				}
80
				}
83
 
81
 
84
				public void onResponseReceived(Request request,
82
				public void onResponseReceived(Request request,
85
						Response response) {
83
						Response response) {
86
					
84
					
87
					final ListeObservation observationData ;
85
					final ListeObservation observationData ;
88
					final JSONValue responseValue = JSONParser.parse(response.getText());
86
					final JSONValue responseValue = JSONParser.parse(response.getText());
89
								
87
								
90
					JSONArray reponse=null;
88
					JSONArray reponse=null;
91
					
89
					
92
					// si c'est un tableau
90
					// si c'est un tableau
93
					if ((reponse=responseValue.isArray()) != null) {
91
					if ((reponse=responseValue.isArray()) != null) {
94
						
92
						
95
						JSONArray observation;
93
						JSONArray observation;
96
						final int taillemax = reponse.size();
94
						final int taillemax = reponse.size();
97
						
95
						
98
						observationData = new ListeObservation(taillemax);
96
						observationData = new ListeObservation(taillemax);
99
						
97
						
100
						for (int i = 0; i < taillemax; i++) {
98
						for (int i = 0; i < taillemax; i++) {
101
							
99
							
102
							if ((observation=reponse.get(i).isArray()) != null) {								
100
							if ((observation=reponse.get(i).isArray()) != null) {								
103
								
101
								
104
								String transmis=((JSONString) observation.get(13)).stringValue();
102
								String transmis=((JSONString) observation.get(13)).stringValue();
105
								String identifiantLocalite=((JSONString) observation.get(14)).toString();
103
								String identifiantLocalite=((JSONString) observation.get(14)).toString();
106
								String nomSaisi=Util.toCelString(((JSONString) observation.get(0)).toString());
104
								String nomSaisi=Util.toCelString(((JSONString) observation.get(0)).toString());
107
								String nomRetenu=Util.toCelString(((JSONString) observation.get(2)).toString());
105
								String nomRetenu=Util.toCelString(((JSONString) observation.get(2)).toString());
108
								String numeroNomenclaturalSaisi=((JSONString) observation.get(1)).stringValue();
106
								String numeroNomenclaturalSaisi=((JSONString) observation.get(1)).stringValue();
109
								String numeroNomenclaturalRetenu=((JSONString) observation.get(3)).stringValue();
107
								String numeroNomenclaturalRetenu=((JSONString) observation.get(3)).stringValue();
110
								String numeroTaxonomique=((JSONString) observation.get(4)).stringValue();
108
								String numeroTaxonomique=((JSONString) observation.get(4)).stringValue();
111
								String famille=Util.toCelString(((JSONString) observation .get(5)).toString());
109
								String famille=Util.toCelString(((JSONString) observation .get(5)).toString());
112
								String localite=Util.toCelString(((JSONString) observation .get(6)).toString());
110
								String localite=Util.toCelString(((JSONString) observation .get(6)).toString());
113
								String lieudit=Util.toCelString(((JSONString) observation .get(9)).toString());
111
								String lieudit=Util.toCelString(((JSONString) observation .get(9)).toString());
114
								String station=Util.toCelString(((JSONString) observation .get(10)).toString());
112
								String station=Util.toCelString(((JSONString) observation .get(10)).toString());
115
								String milieu=Util.toCelString(((JSONString) observation .get(11)).toString());
113
								String milieu=Util.toCelString(((JSONString) observation .get(11)).toString());
116
								String commentaire=Util.toCelString(((JSONString) observation .get(12)).toString());
114
								String commentaire=Util.toCelString(((JSONString) observation .get(12)).toString());
117
								String date=((JSONString) observation .get(8)).stringValue();
115
								String date=((JSONString) observation .get(8)).stringValue();
118
								String numeroOrdre=((JSONString) observation.get(7)).stringValue();
116
								String numeroOrdre=((JSONString) observation.get(7)).stringValue();
119
								
117
								
120
								Observation obs=new Observation(transmis, nomSaisi, nomRetenu, numeroNomenclaturalSaisi, numeroNomenclaturalRetenu ,numeroTaxonomique, famille, localite, identifiantLocalite, lieudit, station, milieu, commentaire, date, numeroOrdre);
118
								Observation obs=new Observation(transmis, nomSaisi, nomRetenu, numeroNomenclaturalSaisi, numeroNomenclaturalRetenu ,numeroTaxonomique, famille, localite, identifiantLocalite, lieudit, station, milieu, commentaire, date, numeroOrdre);
121
			
119
			
122
								observationData.put(obs.getNumeroOrdre(),obs);
120
								observationData.put(obs.getNumeroOrdre(),obs);
-
 
121
								
-
 
122
								
123
							}
123
							}
124
				
124
				
125
						}
125
						}
126
					} else {
126
					} else {
127
						
127
						
128
						observationData = new ListeObservation(0) ;
128
						observationData = new ListeObservation(0) ;
129
					}
129
					}
130
										
130
										
131
					// dans tous les cas on transmet la liste crée au rafraichissable en lui demandant de répandre les données car il est
131
					// dans tous les cas on transmet la liste crée au rafraichissable en lui demandant de répandre les données car il est
132
					// le premier à les recevoir
132
					// le premier à les recevoir
133
					r.rafraichir(observationData,true);				
133
					r.rafraichir(observationData,true);				
134
				}
134
				}
135
			}) ;
135
			}) ;
136
 
136
 
137
		} catch (RequestException e) {
137
		} catch (RequestException e) {
138
			// TODO Auto-generated catch block
138
			// TODO Auto-generated catch block
139
			e.printStackTrace();
139
			e.printStackTrace();
140
		}
140
		}
141
	}
141
	}
142
	
142
	
143
}
143
}