private void reload() { UltimateFestivalOrganizerSoap ufo = UFOService.getInstance(); venues = ufo.getAllVenues().getVenue(); artists = ufo.getAllButDeletedArtists().getArtist(); // Performances performances.clear(); if (performancesSessionBean.getSelectedDate() == null) { return; } // fill with new for (Venue v : venues) { performances.put(v.getId(), new HashMap<>()); for (int hour = 14; hour <= 23; ++hour) { Performance p = new Performance(); p.setVenue(v); Calendar c = new GregorianCalendar(); c.setTime(performancesSessionBean.getSelectedDate()); c.add(Calendar.HOUR_OF_DAY, hour); p.setDateTime(dateToGregorian(c.getTime())); Artist a = new Artist(); a.setId(0); p.setArtist(a); performances.get(v.getId()).put(hour, p); } } // fill with existing List<Performance> allPerformances = ufo.getPerformancesByDate(dateToGregorian(performancesSessionBean.getSelectedDate())) .getPerformance(); for (Performance p : allPerformances) { int venueId = p.getVenue().getId(); int hour = p.getDateTime().getHour(); performances.get(venueId).put(hour, p); } }
private int getVenueRating(Venue venue) { String url = "http://homepages.cs.ncl.ac.uk/d.ingram/TeamProject/getVenueAverage.php"; // Set up connection String result = ""; int resultInt = 0; HttpClient httpclient = new DefaultHttpClient(); HttpPost post = new HttpPost(url); Log.i("help", "point 1"); try { // Add data to ArrayList List<NameValuePair> urlParameters = new ArrayList<NameValuePair>(); urlParameters.add(new BasicNameValuePair("ID", Integer.toString(venue.getId()))); post.setEntity(new UrlEncodedFormEntity(urlParameters)); Log.i("help", "point 2"); // Get the response from HTTP Server HttpResponse response = httpclient.execute(post); Log.i("help", "point 3"); HttpEntity entity = response.getEntity(); Log.i("help", "point 4"); if (entity != null) { // Store response in InputStream InputStream is = entity.getContent(); // Reads the input and encodes using IS0-8859-1 encoding. BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8); // Covert InputStream to String String ans = null; StringBuilder sb = new StringBuilder(); while ((ans = reader.readLine()) != null) { sb.append(ans); } result = sb.toString(); Log.i("Result: ", result); JSONArray jsonResult = (JSONArray) new JSONParser().parse(result); JSONObject jsonObj = (JSONObject) jsonResult.get(0); String resultStr = (String) jsonObj.get("Average"); Log.i("JSON Result: ", resultStr); resultInt = (int) (Math.round(Double.parseDouble(resultStr))); Log.i("Parsed int: ", Integer.toString(resultInt)); return resultInt; } } catch (Exception e) { e.printStackTrace(); Log.i("Fail", "Fail"); } return resultInt; }