Subversion Repositories eFlore/Applications.del

Rev

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

Rev 770 Rev 778
Line 23... Line 23...
23
	private int nbTotalImagesPourLaRecherche;
23
	private int nbTotalImagesPourLaRecherche;
Line 24... Line 24...
24
 
24
 
Line 25... Line 25...
25
	public ImageServiceResultat(JSONValue retourJson) {
25
	public ImageServiceResultat(JSONValue retourJson) {
26
	
-
 
27
		try {
-
 
28
			// TODO ajouter vérifications plus précises
-
 
29
			double total = retourJson.isObject().get("entete").isObject().get("total").isNumber().doubleValue();
-
 
30
			nbTotalImagesPourLaRecherche = (int) total;
-
 
31
 
26
	
32
			JSONObject tableauImg = retourJson.isObject().get("resultats").isObject();
-
 
-
 
27
		try {
-
 
28
			images = new ArrayList<Image>();
-
 
29
			// TODO ajouter vérifications plus précises
-
 
30
			if(retourJson.isObject().get("entete") != null) {
-
 
31
				double total = retourJson.isObject().get("entete").isObject().get("total").isNumber().doubleValue();
33
			images = new ArrayList<Image>();
32
				nbTotalImagesPourLaRecherche = (int) total;
34
			
33
				JSONObject tableauImg = retourJson.isObject().get("resultats").isObject();
35
			java.util.Iterator<String> it = tableauImg.keySet().iterator();
34
				java.util.Iterator<String> it = tableauImg.keySet().iterator();
36
			while (it.hasNext()) {
35
				while (it.hasNext()) {
37
				JSONObject imageJson = tableauImg.get(it.next()).isObject();
-
 
38
				Image image = UtilitairesServiceResultat.parserImageJSON(imageJson);
-
 
39
				
36
					JSONObject imageJson = tableauImg.get(it.next()).isObject();
40
				if (imageJson.get("observation") != null && imageJson.get("observation").isObject() != null) {
-
 
41
					JSONObject observationJson = imageJson.get("observation").isObject();
37
					Image image = parserRetourImage(imageJson);
42
					image.setObservation(UtilitairesServiceResultat.parserObservationEtCreerPropositionDetermination(observationJson));
38
					images.add(image);
-
 
39
				}
43
				}
40
				
-
 
41
			} else {
-
 
42
				JSONArray tableauImg = retourJson.isObject().get("images").isArray();
44
 
43
				nbTotalImagesPourLaRecherche = (int) tableauImg.size();
45
				if (imageJson.get("votes") != null && imageJson.get("votes").isArray() != null) {
44
				for (int i = 0; i < nbTotalImagesPourLaRecherche; i++) {
-
 
45
					JSONObject imageJson = tableauImg.get(i).isObject();
46
					JSONArray votes = imageJson.get("votes").isArray();
46
					Image image = parserRetourImage(imageJson);
47
					image.setVoteProtocoles(UtilitairesServiceResultat.parserVotesProtocoles(votes));
-
 
48
				}
-
 
49
 
47
					images.add(image);
50
				images.add(image);
48
				}
Line 51... Line 49...
51
			}
49
			}
52
		} catch (Exception e) {
50
		} catch (Exception e) {
-
 
51
 
-
 
52
		}
-
 
53
	}
-
 
54
	
-
 
55
	public Image parserRetourImage(JSONObject imageJson) {
-
 
56
		Image image = UtilitairesServiceResultat.parserImageJSON(imageJson);
-
 
57
		
-
 
58
		if (imageJson.get("observation") != null && imageJson.get("observation").isObject() != null) {
-
 
59
			JSONObject observationJson = imageJson.get("observation").isObject();
-
 
60
			image.setObservation(UtilitairesServiceResultat.parserObservationEtCreerPropositionDetermination(observationJson));
-
 
61
		}
-
 
62
 
-
 
63
		if (imageJson.get("protocoles_votes") != null && imageJson.get("protocoles_votes").isObject() != null) {
-
 
64
			JSONObject votes = imageJson.get("protocoles_votes").isObject();
-
 
65
			image.setVoteProtocoles(UtilitairesServiceResultat.parserVotesProtocoles(votes));
-
 
66
		}
Line 53... Line 67...
53
 
67
		
54
		}
68
		return image;
55
	}
69
	}