Subversion Repositories eFlore/Applications.coel

Rev

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

Rev 1417 Rev 1513
Line 1... Line 1...
1
package org.tela_botanica.client.modeles.collection;
1
package org.tela_botanica.client.modeles.collection;
Line -... Line 2...
-
 
2
 
-
 
3
import java.util.HashMap;
2
 
4
 
3
import org.tela_botanica.client.Mediateur;
5
import org.tela_botanica.client.Mediateur;
4
import org.tela_botanica.client.RegistreId;
6
import org.tela_botanica.client.RegistreId;
5
import org.tela_botanica.client.http.JsonRestRequestBuilder;
7
import org.tela_botanica.client.http.JsonRestRequestBuilder;
6
import org.tela_botanica.client.http.JsonRestRequestCallback;
8
import org.tela_botanica.client.http.JsonRestRequestCallback;
Line 12... Line 14...
12
 
14
 
13
import com.extjs.gxt.ui.client.Registry;
15
import com.extjs.gxt.ui.client.Registry;
14
import com.google.gwt.core.client.GWT;
16
import com.google.gwt.core.client.GWT;
15
import com.google.gwt.http.client.URL;
17
import com.google.gwt.http.client.URL;
-
 
18
import com.google.gwt.json.client.JSONArray;
16
import com.google.gwt.json.client.JSONArray;
19
import com.google.gwt.json.client.JSONObject;
Line 17... Line 20...
17
import com.google.gwt.json.client.JSONValue;
20
import com.google.gwt.json.client.JSONValue;
18
 
21
 
Line 26... Line 29...
26
		if (Mediateur.DEBUG) System.out.println("|| CollectionAPublicationAsyncDao > vueARafraichir = "+vueARafraichirCourrante.getClass().toString());
29
		if (Mediateur.DEBUG) System.out.println("|| CollectionAPublicationAsyncDao > vueARafraichir = "+vueARafraichirCourrante.getClass().toString());
27
		vueARafraichir = vueARafraichirCourrante;
30
		vueARafraichir = vueARafraichirCourrante;
28
		utilisateurId = ((Mediateur) Registry.get(RegistreId.MEDIATEUR)).getUtilisateurId();
31
		utilisateurId = ((Mediateur) Registry.get(RegistreId.MEDIATEUR)).getUtilisateurId();
29
	}
32
	}
Line 30... Line 33...
30
	
33
	
-
 
34
	public void selectionner(final boolean paginationProgressive, final String collectionId, final String recherche, final int start, final int nbElements, final Integer seqId) {
31
	public void selectionner(final String collectionId, final Integer seqId) {
35
 
Line 32... Line 36...
32
		String[] parametres = {collectionId};
36
		String[] parametres = {collectionId};
-
 
37
		
-
 
38
		HashMap<String, String> restrictions = new HashMap<String, String>();
-
 
39
		
-
 
40
		if (nbElements != -1)	{
-
 
41
			restrictions.put("limit", String.valueOf(nbElements));
-
 
42
		}
-
 
43
		
-
 
44
		restrictions.put("orderby", "cpu_fmt_auteur");
-
 
45
 
Line -... Line 46...
-
 
46
		/** GESTION DE LA REQUETE dans le cas d'une liste paginée progressive **/
-
 
47
		if (paginationProgressive) {
-
 
48
 
-
 
49
			/** DEFINITION DU TUPLE DE DEPART **/
-
 
50
			restrictions.put("start", String.valueOf(start));
-
 
51
			
-
 
52
			/** CONSTRUCTION DE LA REQUETE **/
-
 
53
    		final JsonRestRequestBuilder rb = UtilDAO.construireRequete(SERVICE_NOM, parametres, restrictions);
-
 
54
    		
-
 
55
    		/** ENVOI DE LA REQUETE **/
-
 
56
    		rb.envoyerRequete(null, new JsonRestRequestCallback()
-
 
57
    		{
-
 
58
    			/** RECEPTION DE LA REPONSE **/
-
 
59
    			public void surReponse(JSONValue responseValue)
-
 
60
    			{    				
-
 
61
    				/** Dans le cas d'une liste paginée, vueARafraichir est un objet Proxy.
-
 
62
    				 * On retourne l'objet JSON au proxy afin que ce soit lui qui le traite **/
-
 
63
    				
-
 
64
					if (seqId != null)	{
-
 
65
						if (Mediateur.DEBUG) System.out.println("<-- CollectionAPublicationAsyncDao > Liste paginée, retour au sequenceur");
-
 
66
						Reponse reponseRequete = new Reponse(responseValue, seqId);
-
 
67
						vueARafraichir.rafraichir(reponseRequete);
-
 
68
					}
-
 
69
					else	{
-
 
70
						if (Mediateur.DEBUG) System.out.println("<-- CollectionAPublicationAsyncDao > Liste paginée, retour à "+vueARafraichir.getClass().toString());
-
 
71
						vueARafraichir.rafraichir(responseValue);
-
 
72
					}
-
 
73
    			}
-
 
74
    		});
-
 
75
		}
-
 
76
		/** GESTION DE LA REQUETE dans le cas d'une liste NON paginée progressive **/
-
 
77
		else {
-
 
78
			
-
 
79
			/** DEFINITION DU TUPLE DE DEPART **/
-
 
80
			restrictions.put("start", String.valueOf(start*nbElements));
33
		
81
			
34
		final JsonRestRequestBuilder rb = UtilDAO.construireRequete(SERVICE_NOM, parametres);
82
			final JsonRestRequestBuilder rb = UtilDAO.construireRequete(SERVICE_NOM, parametres, restrictions);
35
 
83
			
-
 
84
			rb.envoyerRequete(null, new JsonRestRequestCallback() {
36
		rb.envoyerRequete(null, new JsonRestRequestCallback() {
85
				@Override
-
 
86
				public void surReponse(JSONValue responseValue) {
37
			@Override
87
					
-
 
88
					Information info = new Information("liste_collection_a_publication");
38
			public void surReponse(JSONValue responseValue) {
89
 
39
				Information info = new Information("liste_collection_a_publication");
90
					if (responseValue != null) {
-
 
91
 
-
 
92
						JSONObject responseObject = responseValue.isObject();
-
 
93
						if (responseObject != null) {
40
				if (responseValue != null) {
94
							// Si la réponse est un tableau, alors c'est une liste de collections qui a été retournée
-
 
95
							if (responseObject.get("collectionsAPublication").isArray() != null) {
41
					// Si la requête est un succès, reception d'un tableau
96
 
42
					if (responseValue.isArray() != null) {
97
								final JSONArray reponse = responseObject.get("collectionsAPublication").isArray();
43
						final JSONArray reponse = responseValue.isArray();
98
								
-
 
99
								// Transformation du tableau JSON réponse en ListeInstitution
44
						// Transformation du tableau JSON réponse en ListeInstitution
100
								CollectionAPublicationListe publications = new CollectionAPublicationListe(reponse);
45
						CollectionAPublicationListe publications = new CollectionAPublicationListe(reponse);
101
								info.setDonnee(0, publications);
-
 
102
								
46
						info.setDonnee(0, publications);
103
								// et on met à jour le demandeur des données
47
						// et on met à jour le demandeur des données
104
								if (seqId != null)	{
-
 
105
									if (Mediateur.DEBUG) System.out.println("<-- CollectionAPublicationAsyncDao > Liste non paginée, retour au sequenceur");
-
 
106
									Reponse reponseRequete = new Reponse(info, seqId);
-
 
107
									vueARafraichir.rafraichir(reponseRequete);
-
 
108
								}
-
 
109
								else	{
-
 
110
									if (Mediateur.DEBUG) System.out.println("<-- CollectionAPublicationAsyncDao > Liste non paginée, retour au sequenceur");
-
 
111
									vueARafraichir.rafraichir(info);
-
 
112
								}
-
 
113
							// Si la réponse est un objet, alors c'est une unique collection qui a été retournée
48
						if (seqId != null)	{
114
							} else if (responseObject.get("collectionsAPublication").isObject() != null) {
49
							Reponse reponseRequete = new Reponse(info, seqId);
115
								GWT.log(rb.getUrl()+"\n\tLa réponse n'est pas un tableau JSON et vaut : "+responseValue.toString(), null);
-
 
116
							}
-
 
117
						}
-
 
118
					} else {
50
							vueARafraichir.rafraichir(reponseRequete);
119
						// Dans le cas, où nous demandons toutes les institutions et qu'il n'y en a pas, nous retournons un objet vide
51
						}
120
						if (collectionId == null) {
52
						else	{
-
 
53
							vueARafraichir.rafraichir(info);
-
 
54
						}
-
 
55
					} else {
-
 
56
						GWT.log(rb.getUrl()+"\n\tLa réponse n'est pas un talbeau JSON et vaut : "+responseValue.toString(), null);
-
 
57
					}
-
 
58
				} else {
-
 
59
					if (collectionId == null) {
-
 
60
						// Dans le cas, où nous demandons toutes les relations Collection à Publication et qu'il n'y en a pas, nous retournons un message d'information
121
							info.setMessage("Aucune relations entre la collection et les publications");
61
						info.setMessage("Aucune relations entre la collection et les publications");
122
							vueARafraichir.rafraichir(info);
62
						vueARafraichir.rafraichir(info);
123
						}
63
					}
124
					}
64
				}
125
				}
Line 65... Line 126...
65
			}
126
			});
66
		});
127
		}
67
	}
128
	}	
68
 
129