Subversion Repositories eFlore/Applications.del

Rev

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

Rev 1496 Rev 1689
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.modeles.Observation;
-
 
6
import org.tela_botanica.del.client.modeles.VoteDetermination;
-
 
7
import org.tela_botanica.del.client.services.rest.async.DepublicationObservationCallBack;
5
import org.tela_botanica.del.client.services.rest.async.ObservationsCallback;
8
import org.tela_botanica.del.client.services.rest.async.ObservationsCallback;
6
import org.tela_botanica.del.client.services.rest.async.PHPCallback.ModeRequete;
9
import org.tela_botanica.del.client.services.rest.async.PHPCallback.ModeRequete;
7
 
-
 
8
import org.tela_botanica.del.client.services.RequestBuilderWithCredentials;
10
import org.tela_botanica.del.client.services.RequestBuilderWithCredentials;
9
 
11
 
10
public class ObservationServiceConcret implements ObservationService {
12
public class ObservationServiceConcret implements ObservationService {
11
 
13
 
12
	private String baseUrl;
14
	private String baseUrl;
13
 
15
 
14
	public ObservationServiceConcret() {
16
	public ObservationServiceConcret() {
15
		Config config = new Config();
17
		Config config = new Config();
16
		this.baseUrl = config.getServiceBaseUrl();
18
		this.baseUrl = config.getServiceBaseUrl();
17
	}
19
	}
18
	
20
	
19
	public ObservationServiceConcret(Config config) {
21
	public ObservationServiceConcret(Config config) {
20
		this.baseUrl = config.getServiceBaseUrl();
22
		this.baseUrl = config.getServiceBaseUrl();
21
	}
23
	}
22
	
24
	
23
	@Override
25
	@Override
24
	public void getObservations(InformationsRecherche infos, int debut, int fin, String statut, ObservationsCallback callback) {
26
	public void getObservations(InformationsRecherche infos, int debut, int fin, String statut, ObservationsCallback callback) {
25
		RequestBuilderWithCredentials rb = new RequestBuilderWithCredentials(RequestBuilderWithCredentials.GET, baseUrl + "observations" + assemblerChaineRequete(infos, debut, fin, statut));
27
		RequestBuilderWithCredentials rb = new RequestBuilderWithCredentials(RequestBuilderWithCredentials.GET, baseUrl + "observations" + assemblerChaineRequete(infos, debut, fin, statut));
26
		callback.setMode(ModeRequete.LECTURE);
28
		callback.setMode(ModeRequete.LECTURE);
27
		try {
29
		try {
28
			rb.sendRequest(null, callback);
30
			rb.sendRequest(null, callback);
29
		} catch (Exception e) {
31
		} catch (Exception e) {
30
			// TODO: handle exception
32
			// TODO: handle exception
31
		}
33
		}
32
	}
34
	}
33
 
35
 
34
	private String assemblerChaineRequete(InformationsRecherche infos, int debut, int fin, String statut) {
36
	private String assemblerChaineRequete(InformationsRecherche infos, int debut, int fin, String statut) {
35
 
-
 
36
		String chaineRequete = "?navigation.depart=" + debut + "&navigation.limite=" + (fin - debut);
37
		String chaineRequete = "?navigation.depart=" + debut + "&navigation.limite=" + (fin - debut);
37
		if (statut != null && !statut.equals("tous")) {
38
		if (statut != null && !statut.equals("tous")) {
38
			chaineRequete += "&masque.type=" + statut;
39
			chaineRequete += "&masque.type=" + statut;
39
		}
40
		}
40
		chaineRequete+= infos.versChaineRequete();
41
		chaineRequete+= infos.versChaineRequete();
41
 
42
 
42
		return chaineRequete;
43
		return chaineRequete;
43
	}
44
	}
44
 
45
 
45
	@Override
46
	@Override
46
	public void getObservation(String idObservation,
47
	public void getObservation(String idObservation, ObservationsCallback callback) {
47
			ObservationsCallback callback) {
-
 
48
		RequestBuilderWithCredentials rb = new RequestBuilderWithCredentials(RequestBuilderWithCredentials.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
	}
-
 
56
	
-
 
57
	public void depublier(Observation observation, DepublicationObservationCallBack callback) {
-
 
58
		String urlService = baseUrl+"observations/"+observation.getId();
-
 
59
		RequestBuilderWithCredentials rb = new RequestBuilderWithCredentials(RequestBuilderWithCredentials.POST, urlService);
-
 
60
				
-
 
61
		callback.setMode(ModeRequete.MODIFICATION);
-
 
62
		String chainePost = "transmission=0";
-
 
63
		try {
-
 
64
			rb.sendRequest(chainePost, callback);
-
 
65
		} catch (Exception e) {
-
 
66
			//TODO: quoi faire si la requete est mal formée coté client avant d'être envoyée ?
-
 
67
		}
55
	}
68
	}
56
}
69
}