Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 76 Rev 77
1
package org.tela_botanica.client.modeles;
1
package org.tela_botanica.client.modeles;
2
 
2
 
3
import org.tela_botanica.client.interfaces.Rafraichissable;
3
import org.tela_botanica.client.interfaces.Rafraichissable;
4
import org.tela_botanica.client.observation.ObservationModele;
4
import org.tela_botanica.client.observation.ObservationModele;
5
 
5
 
6
import com.google.gwt.http.client.Request;
6
import com.google.gwt.http.client.Request;
7
import com.google.gwt.http.client.RequestBuilder;
7
import com.google.gwt.http.client.RequestBuilder;
8
import com.google.gwt.http.client.RequestCallback;
8
import com.google.gwt.http.client.RequestCallback;
9
import com.google.gwt.http.client.RequestException;
9
import com.google.gwt.http.client.RequestException;
10
import com.google.gwt.http.client.Response;
10
import com.google.gwt.http.client.Response;
11
import com.google.gwt.http.client.URL;
11
import com.google.gwt.http.client.URL;
12
 
12
 
13
/**
13
/**
14
 * DAO d'accès a une observation
14
 * DAO d'accès a une observation
15
 * 
15
 * 
16
 * @author aurelien
16
 * @author aurelien
17
 * 
17
 * 
18
 */
18
 */
19
public class ObservationAsynchroneDAO {
19
public class ObservationAsynchroneDAO {
20
 
20
 
21
	/**
21
	/**
22
	 * Le modele associé au DAO
22
	 * Le modele associé au DAO
23
	 */
23
	 */
24
	private ObservationModele oModele = null;
24
	private ObservationModele oModele = null;
25
 
25
 
26
	public ObservationAsynchroneDAO(ObservationModele obs) {
26
	public ObservationAsynchroneDAO(ObservationModele obs) {
27
		oModele = obs;
27
		oModele = obs;
28
	}
28
	}
29
 
29
 
30
	/**
30
	/**
31
	 * Setteur pour le modèle
31
	 * Setteur pour le modèle
32
	 * 
32
	 * 
33
	 * @param obs
33
	 * @param obs
34
	 *            le modèle à associer
34
	 *            le modèle à associer
35
	 */
35
	 */
36
	public void setoModele(ObservationModele obs) {
36
	public void setoModele(ObservationModele obs) {
37
		oModele = obs;
37
		oModele = obs;
38
	}
38
	}
39
 
39
 
40
	/**
40
	/**
41
	 * Envoie requete au serveur pour ajouter une observations
41
	 * Envoie requete au serveur pour ajouter une observations
42
	 * 
42
	 * 
43
	 * @param motcle
43
	 * @param motcle
44
	 *            le mots clés à ajouter avec son parent et son identifiant
44
	 *            le mots clés à ajouter avec son parent et son identifiant
45
	 */
45
	 */
46
	
46
	
47
	public void ajouter(final Rafraichissable r, String utilisateur, final Observation obs) {
47
	public void ajouter(final Rafraichissable r, String utilisateur, final Observation obs) {
48
	
48
	
49
		
49
		
50
 
50
 
51
//		private void addElement(String nom_sel, String num_nom_sel, String nom_ret,
51
//		private void addElement(String nom_sel, String num_nom_sel, String nom_ret,
52
	//			String num_nom_ret, String num_taxon, String famille,final String loc, String id_location,String dat, String lieu, String sta,  String mil, String comment) {
52
	//			String num_nom_ret, String num_taxon, String famille,final String loc, String id_location,String dat, String lieu, String sta,  String mil, String comment) {
53
 
53
 
54
			RequestBuilder rb = new RequestBuilder(RequestBuilder.POST,oModele.getConfig().getServiceBaseUrl()+ "/Inventory/") ;
54
			RequestBuilder rb = new RequestBuilder(RequestBuilder.POST,oModele.getConfig().getServiceBaseUrl()+ "/Inventory/") ;
55
			
55
			
56
			String postData = "identifiant="
56
			String postData = "identifiant="
57
				+ utilisateur + "&nom_sel=" + URL.encodeComponent(obs.getNomSaisi()) + "&num_nom_sel=" + obs.getNumeroNomenclaturalSaisi()
57
				+ utilisateur + "&nom_sel=" + URL.encodeComponent(obs.getNomSaisi()) + "&num_nom_sel=" + obs.getNumeroNomenclaturalSaisi()
58
				+ "&location=" + URL.encodeComponent(obs.getLocalite()) + "&id_location=" + obs.getIdentifiantLocalite() + "&date_observation=" +  obs.getDate()
58
				+ "&location=" + URL.encodeComponent(obs.getLocalite()) + "&id_location=" + obs.getIdentifiantLocalite() + "&date_observation=" +  obs.getDate()
59
				+ "&lieudit="+ URL.encodeComponent(obs.getLieudit()) + "&station="+ URL.encodeComponent(obs.getStation()) +"&milieu="+ URL.encodeComponent(obs.getMilieu()) + "&commentaire="+ URL.encodeComponent(obs.getCommentaire()) ;
59
				+ "&lieudit="+ URL.encodeComponent(obs.getLieudit()) + "&station="+ URL.encodeComponent(obs.getStation()) +"&milieu="+ URL.encodeComponent(obs.getMilieu()) + "&commentaire="+ URL.encodeComponent(obs.getCommentaire()) ;
60
 
60
 
61
			
61
			
62
			try {
62
			try {
63
				
63
				
64
				rb.sendRequest(postData, new RequestCallback() {
64
				rb.sendRequest(postData, new RequestCallback() {
65
 
65
 
66
					public void onError(Request request, Throwable exception) {
66
					public void onError(Request request, Throwable exception) {
67
						// TODO Auto-generated method stub
67
						// TODO Auto-generated method stub
68
						
68
						
69
					}
69
					}
70
 
70
 
71
					public void onResponseReceived(Request request,
71
					public void onResponseReceived(Request request,
72
							Response response) {
72
							Response response) {
73
						
73
						
74
						r.rafraichir(obs,true);
74
						r.rafraichir(obs,true);
75
						
75
						
76
					}
76
					}
77
					
77
					
78
					
78
					
79
				}) ;
79
				}) ;
80
				
80
				
81
			} catch (RequestException e) {
81
			} catch (RequestException e) {
82
				
82
				
83
		}
83
		}
84
	}
84
	}
85
	
85
	
86
	/**
86
	/**
87
	 * Envoie requete au serveur pour modifier une observations
87
	 * Envoie requete au serveur pour modifier une observations
88
	 * 
88
	 * 
89
	 * @param motcle
89
	 * @param motcle
90
	 *            le mots clés à ajouter avec son parent et son identifiant
90
	 *            le mots clés à ajouter avec son parent et son identifiant
91
	 */
91
	 */
92
	
92
	
93
	public void modifier(final Rafraichissable r, String utilisateur, final Observation obs, final String numeroOrdre) {
93
	public void modifier(final Rafraichissable r, String utilisateur, final Observation obs, final String numeroOrdre) {
94
	
94
	
95
 
95
 
96
		
96
		
97
//		private void addElement(String nom_sel, String num_nom_sel, String nom_ret,
97
//		private void addElement(String nom_sel, String num_nom_sel, String nom_ret,
98
	//			String num_nom_ret, String num_taxon, String famille,final String loc, String id_location,String dat, String lieu, String sta,  String mil, String comment) {
98
	//			String num_nom_ret, String num_taxon, String famille,final String loc, String id_location,String dat, String lieu, String sta,  String mil, String comment) {
99
 
99
 
100
			RequestBuilder rb = new RequestBuilder(RequestBuilder.POST,oModele.getConfig().getServiceBaseUrl()+ "/Inventory/" + utilisateur + "/" + numeroOrdre + "/") ;
100
			RequestBuilder rb = new RequestBuilder(RequestBuilder.POST,oModele.getConfig().getServiceBaseUrl()+ "/Inventory/" + utilisateur + "/" + numeroOrdre + "/") ;
101
			
101
			
102
			String postData = "identifiant="
102
			String postData = "identifiant="
103
				+ utilisateur + "&nom_sel=" + URL.encodeComponent(obs.getNomSaisi()) + "&num_nom_sel=" + obs.getNumeroNomenclaturalSaisi()
103
				+ utilisateur + "&nom_sel=" + URL.encodeComponent(obs.getNomSaisi()) + "&num_nom_sel=" + obs.getNumeroNomenclaturalSaisi()
104
				+ "&location=" + URL.encodeComponent(obs.getLocalite()) + "&id_location=" + obs.getIdentifiantLocalite() + "&date_observation=" +  obs.getDate()
104
				+ "&location=" + URL.encodeComponent(obs.getLocalite()) + "&id_location=" + obs.getIdentifiantLocalite() + "&date_observation=" +  obs.getDate()
105
				+ "&lieudit="+ URL.encodeComponent(obs.getLieudit()) + "&station="+ URL.encodeComponent(obs.getStation()) +"&milieu="+ URL.encodeComponent(obs.getMilieu()) + "&commentaire="+ URL.encodeComponent(obs.getCommentaire()) ;
105
				+ "&lieudit="+ URL.encodeComponent(obs.getLieudit()) + "&station="+ URL.encodeComponent(obs.getStation()) +"&milieu="+ URL.encodeComponent(obs.getMilieu()) + "&commentaire="+ URL.encodeComponent(obs.getCommentaire()) ;
106
 
106
 
107
			
107
			
108
			try {
108
			try {
109
				
109
				
110
				rb.sendRequest(postData, new RequestCallback() {
110
				rb.sendRequest(postData, new RequestCallback() {
111
 
111
 
112
					public void onError(Request request, Throwable exception) {
112
					public void onError(Request request, Throwable exception) {
113
						// TODO Auto-generated method stub
113
						// TODO Auto-generated method stub
114
						
114
						
115
					}
115
					}
116
 
116
 
117
					public void onResponseReceived(Request request,
117
					public void onResponseReceived(Request request,
118
							Response response) {
118
							Response response) {
119
						
119
						
120
						r.rafraichir(numeroOrdre,true);
120
						r.rafraichir(numeroOrdre,true);
121
						
121
						
122
					}
122
					}
123
					
123
					
124
					
124
					
125
				}) ;
125
				}) ;
126
				
126
				
127
			} catch (RequestException e) {
127
			} catch (RequestException e) {
128
				
128
				
129
		}
129
		}
130
		
130
		
131
	
131
	
132
	
132
	
133
	}
133
	}
-
 
134
 
-
 
135
	public void supprimer(Rafraichissable r, String identifiant, String numeroOrdre) {
-
 
136
		
-
 
137
		String postData = "";
-
 
138
		postData += "&action=DELETE";
-
 
139
 
-
 
140
		// on envoie un post avec l'id de l'image à supprimer
-
 
141
		RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, oModele
-
 
142
				.getConfig().getServiceBaseUrl()
-
 
143
				+ "/inventory/"
-
 
144
				+ identifiant
-
 
145
				+ "/"
-
 
146
				+ numeroOrdre);
-
 
147
 
-
 
148
		try {
-
 
149
			rb.sendRequest(postData, new RequestCallback() {
-
 
150
 
-
 
151
				public void onError(Request request, Throwable exception) {
-
 
152
					// TODO Auto-generated method stub
-
 
153
 
-
 
154
				}
-
 
155
 
-
 
156
				public void onResponseReceived(Request request,
-
 
157
						Response response) {
-
 
158
 
-
 
159
					if (response.getText().equals("OK")) {
-
 
160
						
-
 
161
 
-
 
162
					} else {
-
 
163
						com.google.gwt.user.client.Window
-
 
164
								.alert("Problème lors de la mise à jour des données");
-
 
165
						return ;
-
 
166
					}
-
 
167
				}
-
 
168
 
-
 
169
			});
-
 
170
			
-
 
171
			r.rafraichir("OK", true) ;
-
 
172
 
-
 
173
		} catch (RequestException e) {
-
 
174
			// TODO Auto-generated catch block
-
 
175
			e.printStackTrace();
-
 
176
		}
-
 
177
		
-
 
178
	}
134
	
179
	
135
}
180
}