Subversion Repositories eFlore/Applications.del

Rev

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

Rev 1467 Rev 1496
1
package org.tela_botanica.del.client.services.rest;
1
package org.tela_botanica.del.client.services.rest;
2
 
2
 
3
import org.tela_botanica.del.client.config.Config;
3
import org.tela_botanica.del.client.config.Config;
4
import org.tela_botanica.del.client.modeles.InformationsRecherche;
4
import org.tela_botanica.del.client.modeles.InformationsRecherche;
5
import org.tela_botanica.del.client.services.rest.async.ObservationsCallback;
5
import org.tela_botanica.del.client.services.rest.async.ObservationsCallback;
6
import org.tela_botanica.del.client.services.rest.async.PHPCallback.ModeRequete;
6
import org.tela_botanica.del.client.services.rest.async.PHPCallback.ModeRequete;
7
 
7
 
8
import com.google.gwt.http.client.RequestBuilder;
8
import org.tela_botanica.del.client.services.RequestBuilderWithCredentials;
9
 
9
 
10
public class ObservationServiceConcret implements ObservationService {
10
public class ObservationServiceConcret implements ObservationService {
11
 
11
 
12
	private String baseUrl;
12
	private String baseUrl;
13
 
13
 
14
	public ObservationServiceConcret() {
14
	public ObservationServiceConcret() {
15
		Config config = new Config();
15
		Config config = new Config();
16
		this.baseUrl = config.getServiceBaseUrl();
16
		this.baseUrl = config.getServiceBaseUrl();
17
	}
17
	}
18
	
18
	
19
	public ObservationServiceConcret(Config config) {
19
	public ObservationServiceConcret(Config config) {
20
		this.baseUrl = config.getServiceBaseUrl();
20
		this.baseUrl = config.getServiceBaseUrl();
21
	}
21
	}
22
	
22
	
23
	@Override
23
	@Override
24
	public void getObservations(InformationsRecherche infos, int debut, int fin, String statut, ObservationsCallback callback) {
24
	public void getObservations(InformationsRecherche infos, int debut, int fin, String statut, ObservationsCallback callback) {
25
		RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, baseUrl + "observations" + assemblerChaineRequete(infos, debut, fin, statut));
25
		RequestBuilderWithCredentials rb = new RequestBuilderWithCredentials(RequestBuilderWithCredentials.GET, baseUrl + "observations" + assemblerChaineRequete(infos, debut, fin, statut));
26
		callback.setMode(ModeRequete.LECTURE);
26
		callback.setMode(ModeRequete.LECTURE);
27
		try {
27
		try {
28
			rb.sendRequest(null, callback);
28
			rb.sendRequest(null, callback);
29
		} catch (Exception e) {
29
		} catch (Exception e) {
30
			// TODO: handle exception
30
			// TODO: handle exception
31
		}
31
		}
32
	}
32
	}
33
 
33
 
34
	private String assemblerChaineRequete(InformationsRecherche infos, int debut, int fin, String statut) {
34
	private String assemblerChaineRequete(InformationsRecherche infos, int debut, int fin, String statut) {
35
 
35
 
36
		String chaineRequete = "?navigation.depart=" + debut + "&navigation.limite=" + (fin - debut);
36
		String chaineRequete = "?navigation.depart=" + debut + "&navigation.limite=" + (fin - debut);
37
		if (statut != null && !statut.equals("tous")) {
37
		if (statut != null && !statut.equals("tous")) {
38
			chaineRequete += "&masque.type=" + statut;
38
			chaineRequete += "&masque.type=" + statut;
39
		}
39
		}
40
		chaineRequete+= infos.versChaineRequete();
40
		chaineRequete+= infos.versChaineRequete();
41
 
41
 
42
		return chaineRequete;
42
		return chaineRequete;
43
	}
43
	}
44
 
44
 
45
	@Override
45
	@Override
46
	public void getObservation(String idObservation,
46
	public void getObservation(String idObservation,
47
			ObservationsCallback callback) {
47
			ObservationsCallback callback) {
48
		RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, baseUrl + "observations/"+idObservation);
48
		RequestBuilderWithCredentials rb = new RequestBuilderWithCredentials(RequestBuilderWithCredentials.GET, baseUrl + "observations/"+idObservation);
49
		callback.setMode(ModeRequete.LECTURE);
49
		callback.setMode(ModeRequete.LECTURE);
50
		try {
50
		try {
51
			rb.sendRequest(null, callback);
51
			rb.sendRequest(null, callback);
52
		} catch (Exception e) {
52
		} catch (Exception e) {
53
			// TODO: handle exception
53
			// TODO: handle exception
54
		}
54
		}
55
	}
55
	}
56
}
56
}