Subversion Repositories eFlore/Applications.cel

Rev

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

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