Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 1293 Rev 1542
Line 74... Line 74...
74
		if ((referentielCommuneDataFromCache=getFromCache(critere))!=null) {
74
		if ((referentielCommuneDataFromCache=getFromCache(critere))!=null) {
75
			r.rafraichir(referentielCommuneDataFromCache,true);  
75
			r.rafraichir(referentielCommuneDataFromCache,true);  
76
	    }
76
	    }
Line 77... Line 77...
77
	    
77
	    
78
		else {
-
 
79
	    	  
-
 
80
	    	  
-
 
81
	  
-
 
82
		
78
		else {
83
		RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, Configuration.getServiceBaseUrl() + "/LocationSearch/" + URL.encodeComponent(critere));
-
 
84
		
79
			RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, Configuration.getServiceBaseUrl() + "/LocationSearch/" + URL.encodeComponent(critere));
85
		try {
80
			try {
86
			
81
				
87
			rb.sendRequest(null, new RequestCallback() {
82
				rb.sendRequest(null, new RequestCallback() {
88
 
83
	
89
				@Override
84
					@Override
90
				public void onError(final Request request, final Throwable exception) {
85
					public void onError(final Request request, final Throwable exception) {
91
					// TODO Auto-generated method stub
-
 
92
					
-
 
93
				}
-
 
94
 
-
 
95
				@Override
-
 
96
				public void onResponseReceived(final Request request,
-
 
97
						final Response response) {
-
 
98
					
-
 
99
					final ListeReferentielCommune referentielCommuneData;					
-
 
100
					final JSONValue responseValue = JSONParser.parse(response.getText());					
-
 
101
					JSONArray reponse = null;
-
 
102
 
-
 
103
					// si c'est un tableau
-
 
Line -... Line 86...
-
 
86
						// TODO Auto-generated method stub
-
 
87
						
104
					if ((reponse = responseValue.isArray()) != null) {
88
					}
-
 
89
	
105
						
90
					@Override
Line -... Line 91...
-
 
91
					public void onResponseReceived(final Request request,
-
 
92
							final Response response) {
-
 
93
						
-
 
94
						final ListeReferentielCommune referentielCommuneData;					
-
 
95
						final JSONValue responseValue = JSONParser.parse(response.getText());					
-
 
96
						JSONArray reponse = null;
-
 
97
	
-
 
98
						// si c'est un tableau
-
 
99
						if ((reponse = responseValue.isArray()) != null) {
-
 
100
							
106
						JSONArray communes;
101
							JSONArray communes;
-
 
102
							final int taillemax = reponse.size();
-
 
103
							
-
 
104
							referentielCommuneData = new ListeReferentielCommune(taillemax);
-
 
105
							
-
 
106
							for (int i = 0; i < taillemax; i++) {
-
 
107
								if ((communes = reponse.get(i).isArray()) != null) {
-
 
108
									String commune = ((JSONString) communes.get(0)).stringValue();
-
 
109
									String departement  = ((JSONString) communes.get(1)).stringValue();
-
 
110
									ReferentielCommune com = new ReferentielCommune(commune, departement);		
-
 
111
									referentielCommuneData.put(com.getCommune() + com.getDepartement(), com);			
-
 
112
								}	
-
 
113
							}
-
 
114
						} else {					
-
 
115
							referentielCommuneData = new ListeReferentielCommune(0);
Line 107... Line -...
107
						final int taillemax = reponse.size();
-
 
108
						
-
 
109
						referentielCommuneData = new ListeReferentielCommune(taillemax);
-
 
110
						
-
 
111
						for (int i = 0; i < taillemax; i++) {
-
 
112
							if ((communes = reponse.get(i).isArray()) != null) {
-
 
113
								String commune = ((JSONString) communes.get(0)).stringValue();
-
 
114
								String departement  = ((JSONString) communes.get(1)).stringValue();
-
 
115
								ReferentielCommune com = new ReferentielCommune(commune, departement);		
-
 
116
								referentielCommuneData.put(com.getCommune() + com.getDepartement(), com);			
-
 
117
							}	
116
						}					
118
						}
-
 
119
					} else {					
-
 
Line 120... Line 117...
120
						referentielCommuneData = new ListeReferentielCommune(0);
117
						addToCache(critere, referentielCommuneData);
Line 121... Line -...
121
					}					
-
 
122
					addToCache(critere, referentielCommuneData);
-
 
123
					r.rafraichir(referentielCommuneData, true);
118
						r.rafraichir(referentielCommuneData, true);
124
					
-
 
125
				}	
119
						
126
				
120
					}	
127
			});
-
 
128
			
121
					
129
		} catch (RequestException e) {
-
 
130
			
122
				});
Line -... Line 123...
-
 
123
				
131
			e.printStackTrace();
124
			} catch (RequestException e) {			
132
		}
125
				e.printStackTrace();
133
		
126
			}
134
		} // Fin else si pas de cache
127
		} // Fin else si pas de cache
135
		
128
	}
136
	}
129
	
137
	
130
	/**
138
	  private void addToCache(String query, ListeReferentielCommune result)	  {
-
 
139
		  cache.put(query.toLowerCase(),result);
-
 
Line -... Line 131...
-
 
131
	 * Fonction à implémenter dans le futur, lors de l'utilisation de plusieurs 
-
 
132
	 * référentiels de localité
-
 
133
	 */
-
 
134
	@Override
-
 
135
	public void obtenirListeDonnees(Rafraichissable r, String referentiel, String critere) {
-
 
136
		// TODO Auto-generated method stub
-
 
137
	}
140
	  }
138