Subversion Repositories eFlore/Applications.coel

Rev

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

Rev 1428 Rev 1513
Line 6... Line 6...
6
import org.tela_botanica.client.RegistreId;
6
import org.tela_botanica.client.RegistreId;
7
import org.tela_botanica.client.http.JsonRestRequestBuilder;
7
import org.tela_botanica.client.http.JsonRestRequestBuilder;
8
import org.tela_botanica.client.http.JsonRestRequestCallback;
8
import org.tela_botanica.client.http.JsonRestRequestCallback;
9
import org.tela_botanica.client.interfaces.Rafraichissable;
9
import org.tela_botanica.client.interfaces.Rafraichissable;
10
import org.tela_botanica.client.modeles.Information;
10
import org.tela_botanica.client.modeles.Information;
-
 
11
import org.tela_botanica.client.modeles.projet.Projet;
-
 
12
import org.tela_botanica.client.modeles.projet.ProjetListe;
11
import org.tela_botanica.client.modeles.structure.StructureListe;
13
import org.tela_botanica.client.modeles.structure.StructureListe;
12
import org.tela_botanica.client.synchronisation.Reponse;
14
import org.tela_botanica.client.synchronisation.Reponse;
13
import org.tela_botanica.client.util.Debug;
15
import org.tela_botanica.client.util.Debug;
14
import org.tela_botanica.client.util.UtilDAO;
16
import org.tela_botanica.client.util.UtilDAO;
Line 29... Line 31...
29
		if (Mediateur.DEBUG) System.out.println("|| PublicationAsyncDao > vueARafraichir = "+vueARafraichirCourrante.getClass().toString());
31
		if (Mediateur.DEBUG) System.out.println("|| PublicationAsyncDao > vueARafraichir = "+vueARafraichirCourrante.getClass().toString());
30
		vueARafraichir = vueARafraichirCourrante ;
32
		vueARafraichir = vueARafraichirCourrante ;
31
		utilisateurId = ((Mediateur) Registry.get(RegistreId.MEDIATEUR)).getUtilisateurId();
33
		utilisateurId = ((Mediateur) Registry.get(RegistreId.MEDIATEUR)).getUtilisateurId();
32
	}
34
	}
Line -... Line 35...
-
 
35
 
-
 
36
	
-
 
37
	
-
 
38
	/**
-
 
39
	 * @param paginationProgressive : définit le mode de consultation de la base de données
-
 
40
	 * 			- True :	la consultation des données est progressive, ce qui signifie que la liste est chargée (paginée) au
-
 
41
	 * 						fur et à mesure de la consultation des données par l'utilisateur.
-
 
42
	 * 			- False :	la consultation des données est classique : un seul appel à la base de données est effectué, le retour
-
 
43
	 * 						est renvoyé à l'appelant
-
 
44
	 * 			// FIXME : si la taille de la liste est supérieure à la limite du JREST (150), ce deuxieme mode ne fonctionne pas efficacement (on ne voit pas les enregistrement suivants)
33
 
45
	 */
-
 
46
	public void selectionner(final boolean paginationProgressive, final String publicationId, String projetId, String nomComplet, final int start, final int nbElements, final Integer seqId) {
-
 
47
		
34
	public void selectionner(final String publicationId, String projetId, String nomComplet, final int nbElements, final int pageCourante, final Integer seqId) {
48
		String nom = (nomComplet == null) ? "%" : nomComplet+"%";
35
		String[] parametres = {projetId, publicationId, nomComplet};
49
		String[] param = {publicationId, projetId, nom};
36
 
50
		
37
		HashMap<String, String> restrictions = new HashMap<String, String>();
51
		HashMap<String, String> restrictions = new HashMap<String, String>();
38
		restrictions.put("orderby", "cpu_titre");
-
 
-
 
52
		restrictions.put("orderby", "cpu_fmt_nom_complet");
39
		restrictions.put("start", String.valueOf(pageCourante*nbElements));
53
		
40
		if (nbElements != -1)	{
54
		if (nbElements != -1) {
41
			restrictions.put("limit", String.valueOf(nbElements));
55
			restrictions.put("limit", String.valueOf(nbElements));
Line 42... Line 56...
42
		}
56
		}
43
		
57
		
-
 
58
		/** GESTION DE LA REQUETE dans le cas d'une liste paginée progressive **/
44
		final JsonRestRequestBuilder rb = UtilDAO.construireRequete(SERVICE_NOM, parametres, restrictions);
59
		if (paginationProgressive) {
45
		rb.envoyerRequete(null, new JsonRestRequestCallback() {
60
 
-
 
61
			/** DEFINITION DU TUPLE DE DEPART **/
46
			@Override
62
			restrictions.put("start", String.valueOf(start));
47
			public void surReponse(JSONValue responseValue) {
63
			
-
 
64
			/** CONSTRUCTION DE LA REQUETE **/
48
				if (responseValue != null) {
65
    		final JsonRestRequestBuilder rb = UtilDAO.construireRequete(SERVICE_NOM, param, restrictions);
49
					// Si la requête est un succès, réception d'un objet ou d'un tableau
66
 
-
 
67
    		/** ENVOI DE LA REQUETE **/
50
					JSONArray responseArray = responseValue.isArray();
68
    		rb.envoyerRequete(null, new JsonRestRequestCallback()
51
					if (responseArray.get(1).isObject() != null) {
69
    		{
-
 
70
    			/** RECEPTION DE LA REPONSE **/
52
						final JSONObject reponse = responseArray.get(1).isObject();
71
    			public void surReponse(JSONValue responseValue)
53
						// Transformation du tableau JSON réponse en ListeInstitution
72
    			{
54
						Publication publication = new Publication(reponse);
73
    				/** Dans le cas d'une liste paginée, vueARafraichir est un objet Proxy.
-
 
74
    				 * On retourne l'objet JSON au proxy afin que ce soit lui qui le traite **/
55
						// et on met à jour le demandeur des données
75
					if (seqId != null)	{
56
						if (seqId!=null)	{
76
						if (Mediateur.DEBUG) System.out.println("<-- PublicationAsyncDao > Liste paginée, retour au sequenceur");
-
 
77
						Reponse reponseRequete = new Reponse(responseValue, seqId);
57
							Reponse reponseRequete = new Reponse(publication, seqId);
78
						vueARafraichir.rafraichir(reponseRequete);
-
 
79
					}
58
							vueARafraichir.rafraichir(reponseRequete);
80
					else	{
59
						} else {
81
						if (Mediateur.DEBUG) System.out.println("<-- PublicationAsyncDao > Liste paginée, retour à "+vueARafraichir.getClass().toString());
-
 
82
						vueARafraichir.rafraichir(responseValue);
-
 
83
					}
-
 
84
    			}
-
 
85
    		});
-
 
86
		}
60
							vueARafraichir.rafraichir(publication);
87
		/** GESTION DE LA REQUETE dans le cas d'une liste NON paginée progressive **/
61
						}
88
		else {
62
						
89
			
-
 
90
			/** DEFINITION DU TUPLE DE DEPART **/
63
					} else if (responseArray.get(1).isArray() != null) {
91
			restrictions.put("start", String.valueOf(start*nbElements));			
-
 
92
			
64
						final JSONArray reponse = responseValue.isArray();
93
			final JsonRestRequestBuilder rb = UtilDAO.construireRequete(SERVICE_NOM, param, restrictions);
-
 
94
			
65
						PublicationListe publications;
95
			rb.envoyerRequete(null, new JsonRestRequestCallback() {
-
 
96
				
66
						if (reponse.get(1).isObject() != null)	{
97
				public void surReponse(JSONValue responseValue) {
67
							publications = new PublicationListe(reponse.get(1).isArray());
-
 
68
						} else	{
-
 
Line 69... Line -...
69
							publications = new PublicationListe(reponse.get(1).isArray(), reponse.get(0).isNumber(), vueARafraichir);
-
 
70
						}
98
    				
Line -... Line 99...
-
 
99
					if (responseValue != null) {
-
 
100
						
-
 
101
						JSONObject responseObject = responseValue.isObject();
-
 
102
						
-
 
103
						if (responseObject != null) {
-
 
104
							
-
 
105
							// Si la réponse est un tableau, alors c'est une liste de projets qui a été retournée
-
 
106
							if (responseObject.get("publications").isArray() != null) {
-
 
107
 
-
 
108
								JSONArray reponse = responseObject.get("publications").isArray();
-
 
109
								
-
 
110
								PublicationListe publications;
-
 
111
								publications = new PublicationListe(reponse, responseObject.get("nbElements").isNumber(), vueARafraichir);
-
 
112
								publications.setTaillePage(nbElements);
-
 
113
								publications.setPageCourante(start);							
-
 
114
 
-
 
115
								if (seqId != null) {
-
 
116
									if (Mediateur.DEBUG) System.out.println("<-- PublicationAsyncDao > Liste non paginée, retour au sequenceur");
-
 
117
									Reponse retourRequete = new Reponse(publications, seqId);
-
 
118
									vueARafraichir.rafraichir(retourRequete);
-
 
119
								} else {
-
 
120
									if (Mediateur.DEBUG) System.out.println("<-- PublicationAsyncDao > Liste non paginée, retour à "+vueARafraichir.getClass().toString());
-
 
121
									vueARafraichir.rafraichir(publications);
-
 
122
								}
-
 
123
							
-
 
124
							// Si la réponse est un objet, alors c'est un unique projet qui a été retourné
-
 
125
							} else if (responseObject.get("publications").isObject() != null) {
-
 
126
								
71
						
127
								JSONObject reponse = responseObject.get("publications").isObject();
72
						publications.setTaillePage(nbElements);
128
								// Transformation du tableau JSON réponse en ListeInstitution
73
						publications.setPageCourante(pageCourante);
129
								Publication publication = new Publication(reponse);
-
 
130
								// et on met à jour le demandeur des données
-
 
131
								if (seqId!=null)	{
-
 
132
									Reponse reponseRequete = new Reponse(publication, seqId);
-
 
133
									vueARafraichir.rafraichir(reponseRequete);
74
						
134
								} else {
-
 
135
									vueARafraichir.rafraichir(publication);
-
 
136
								}
-
 
137
							}
-
 
138
						} else {
-
 
139
							GWT.log(rb.getUrl()+"\n\tLa réponse n'est pas un objet ou un tableau JSON et vaut : "+responseValue.toString(), null);
75
						if (seqId!=null)	{
140
						}
76
							Reponse reponseRequete = new Reponse(publications, seqId);
141
					} else {						
77
							vueARafraichir.rafraichir(reponseRequete);
-
 
78
						} else {
-
 
79
							vueARafraichir.rafraichir(publications);
-
 
80
						}
-
 
81
						
-
 
82
					} else {
-
 
83
						GWT.log("La réponse n'est pas un objet ou un talbeau JSON et vaut : "+responseValue.toString(), null);
-
 
84
					}
-
 
85
				} else {
-
 
86
					// Dans le cas, où nous demandons toutes les publication et qu'il n'y en a pas, nous retournons un objet vide
142
						if (publicationId == null) {
87
					if (publicationId == null) {
143
							PublicationListe publications = new PublicationListe(0);
88
						PublicationListe publications = new PublicationListe(0);
144
							vueARafraichir.rafraichir(publications);
89
						vueARafraichir.rafraichir(publications);
145
						}
90
					}
146
					}
Line 91... Line 147...
91
				}
147
				}
92
			}
148
			});