Subversion Repositories eFlore/Applications.coel

Rev

Rev 682 | Rev 1038 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 682 Rev 773
Line 1... Line 1...
1
package org.tela_botanica.client.modeles;
1
package org.tela_botanica.client.modeles;
Line 2... Line 2...
2
 
2
 
Line -... Line 3...
-
 
3
import java.util.HashMap;
-
 
4
 
3
import java.util.HashMap;
5
import org.tela_botanica.client.http.JsonRestRequestBuilder;
4
 
6
import org.tela_botanica.client.http.JsonRestRequestCallback;
Line 5... Line -...
5
import org.tela_botanica.client.interfaces.Rafraichissable;
-
 
6
import org.tela_botanica.client.util.UtilDAO;
-
 
7
 
-
 
8
import com.google.gwt.core.client.GWT;
-
 
9
import com.google.gwt.http.client.Request;
-
 
10
import com.google.gwt.http.client.RequestBuilder;
-
 
11
import com.google.gwt.http.client.RequestCallback;
7
import org.tela_botanica.client.interfaces.Rafraichissable;
12
import com.google.gwt.http.client.RequestException;
8
import org.tela_botanica.client.util.UtilDAO;
13
import com.google.gwt.http.client.Response;
-
 
14
import com.google.gwt.json.client.JSONArray;
9
 
15
import com.google.gwt.json.client.JSONObject;
10
import com.google.gwt.json.client.JSONArray;
Line 16... Line 11...
16
import com.google.gwt.json.client.JSONParser;
11
import com.google.gwt.json.client.JSONObject;
Line 17... Line 12...
17
import com.google.gwt.json.client.JSONString;
12
import com.google.gwt.json.client.JSONString;
18
import com.google.gwt.json.client.JSONValue;
13
import com.google.gwt.json.client.JSONValue;
19
 
14
 
Line 20... Line -...
20
public class ValeurListeAsyncDao {
-
 
21
	
-
 
22
	private static HashMap<Integer, ValeurListe> ontologieCache = new HashMap<Integer, ValeurListe>();
-
 
23
	private static final String SERVICE_NOM = "CoelValeurListe";
-
 
24
	private Rafraichissable vueARafraichir = null;
15
public class ValeurListeAsyncDao {
25
	
16
	
26
	public ValeurListeAsyncDao() {
17
	private static HashMap<Integer, ValeurListe> ontologieCache = new HashMap<Integer, ValeurListe>();
Line 27... Line 18...
27
		// TODO Auto-generated constructor stub
18
	private static final String SERVICE_NOM = "CoelValeurListe";
28
	}
19
	private Rafraichissable vueARafraichir = null;
29
	
20
	
Line 30... Line 21...
30
	public ValeurListeAsyncDao(Rafraichissable vueCourante) {
21
	public ValeurListeAsyncDao(Rafraichissable vueCourante) {
31
		vueARafraichir = vueCourante;
22
		vueARafraichir = vueCourante;
32
	}
23
	}
33
	
24
	
34
	public void obtenirListe(Integer cle)	{
-
 
35
		selectionner("id", cle, "*", "*");
25
	public void obtenirListe(Integer cle)	{
36
	}
-
 
37
	
26
		selectionner("id", cle, null, null);
38
	public void selectionner(String type, final Integer cleParent, String abv, String idValeur) {
-
 
39
    	if (ontologieCache.containsKey(cleParent)) {
-
 
40
    		vueARafraichir.rafraichir(ontologieCache.get(cleParent));
-
 
41
    	} else {
-
 
42
	    	// Ajout des paramètres et données à selectionner dans l'URL
-
 
43
			String[] parametres = new String[4];
27
	}
44
			parametres[0] = type;
-
 
45
			parametres[1] = cleParent.toString();
-
 
46
			parametres[2] = "*";
28
	
47
	    	if (!type.equals("id"))	{
-
 
48
	    		parametres[2] = abv;
-
 
49
	    	}
-
 
50
	    	parametres[3] = idValeur;
-
 
51
	    	RequestBuilder rb = UtilDAO.construireRequete(SERVICE_NOM, parametres);
29
	public void selectionner(String type, final Integer cleParent, String abv, String idValeur) {
52
	    	
-
 
53
			try {
30
		if (ontologieCache.containsKey(cleParent)) {
54
				rb.sendRequest(null, new RequestCallback() {
-
 
55
	
-
 
56
					public void onError(Request request, Throwable exception) {
-
 
57
						// TODO Auto-generated method stub
-
 
58
	
31
    		vueARafraichir.rafraichir(ontologieCache.get(cleParent));
59
					}
-
 
60
	
-
 
61
					public void onResponseReceived(Request request, Response response) {
32
    	} else {
62
						
33
    		String paramAbv = (type.equals("id") ? null : abv);
63
						final JSONValue responseValue = JSONParser.parse(response.getText());
34
    		String[] parametres = {type, cleParent.toString(), paramAbv, idValeur};
64
	
35
    		final JsonRestRequestBuilder rb = UtilDAO.construireRequete(SERVICE_NOM, parametres);
65
						// Si la requête est un succès, reception d'un tableau
36
    		rb.envoyerRequete(null, new JsonRestRequestCallback() {
66
						if (responseValue.isObject() != null) {
37
    			@Override
67
							
38
    			public void surReponse(JSONValue responseValue) {
68
							try {
39
    				if (responseValue.isObject() != null) {
69
								final JSONObject reponse = responseValue.isObject();
40
						final JSONObject reponse = responseValue.isObject();
70
								JSONString listeId = reponse.get("id").isString();
41
						JSONString listeId = reponse.get("id").isString();
71
								JSONArray listeValeurs = reponse.get("valeurs").isArray();
-
 
72
								if (listeId != null)	{
-
 
73
									// Transformation du tableau JSON réponse en Liste
-
 
74
									ValeurListe liste = new ValeurListe(listeId, listeValeurs);
-
 
75
									// Stockage en cache
42
						JSONArray listeValeurs = reponse.get("valeurs").isArray();
76
									ontologieCache.put(cleParent, liste);
-
 
77
									// et on met à jour le demandeur des données
43
						if (listeId != null)	{
78
									vueARafraichir.rafraichir(liste);
44
							// Transformation du tableau JSON réponse en Liste
79
								}
-
 
80
							} catch (NullPointerException e) {
-
 
81
								e.printStackTrace();
45
							ValeurListe liste = new ValeurListe(listeId, listeValeurs);
82
							}
46
							// Stockage en cache
83
						}
47
							ontologieCache.put(cleParent, liste);
Line 84... Line -...
84
	
-
 
85
					}
48
							// et on met à jour le demandeur des données
86
				});
49
							vueARafraichir.rafraichir(liste);