private void startIteration(String cursorString) { // if (cursorString == null) { // CSVEntry entry = CSVCache.getInstance().getCSV(csvId); // if (entry != null) { // if (entry.getStatus() == CSVEntry.BUILDING_STATUS) { // return; // } // } // } CSVEntry entry = CSVCache.getInstance().getCSV(csvId); if (entry != null) { PersistenceManager pm = PMF.get().getPersistenceManager(); try { ResponseList rl = ResponseManager.getResponse(runId, 0l, null, cursorString); entry = processResponses(pm, rl.getResponses()); if (!(rl.getResponses().isEmpty() || rl.getResumptionToken() == null)) { new CSVGeneration(rl.getResumptionToken(), runId, csvId).scheduleTask(); } else { entry.setStatus(CSVEntry.FINISHED_STATUS); } CSVCache.getInstance().putCSV(csvId, entry); } finally { pm.close(); } } }
public CSVEntry firstIteration() { csvId = UUID.randomUUID().toString(); PersistenceManager pm = PMF.get().getPersistenceManager(); try { ResponseList rl = ResponseManager.getResponse(runId, 0l, null, cursorString); CSVEntry entry = processResponses(pm, rl.getResponses()); if (!(rl.getResponses().isEmpty() || rl.getResumptionToken() == null)) { new CSVGeneration(rl.getResumptionToken(), runId, csvId).scheduleTask(); } else { entry.setStatus(CSVEntry.FINISHED_STATUS); } CSVCache.getInstance().putCSV(csvId, entry); return entry; } finally { pm.close(); } }
private CSVEntry processResponses(PersistenceManager pm, List<Response> responseJDOs) { CSVEntry entry = CSVCache.getInstance().getCSV(csvId); if (entry == null) { entry = new CSVEntry( "Response Identifier;Timestamp;Item Identifier;Response Item Identifier; Account; " + "Image Url; Video Url; Width; Height; Latitude; Longitude; Audio Url;Text; Value \n", CSVEntry.BUILDING_STATUS); } String csv = entry.getCSV(); for (Response responseJDO : responseJDOs) { String value = responseJDO.getResponseValue(); String imageUrl = ""; String audioUrl = ""; String videoUrl = ""; String width = ""; String height = ""; String text = ""; String valueString = ""; String lat = responseJDO.getLat() == null ? "" : "" + responseJDO.getLat().doubleValue(); String lng = responseJDO.getLng() == null ? "" : "" + responseJDO.getLng().doubleValue(); try { org.codehaus.jettison.json.JSONObject json = new org.codehaus.jettison.json.JSONObject(value); if (json.has("imageUrl")) imageUrl = json.getString("imageUrl"); if (json.has("audioUrl")) audioUrl = json.getString("audioUrl"); if (json.has("videoUrl")) videoUrl = json.getString("videoUrl"); if (json.has("width")) width = "" + json.getInt("width"); if (json.has("height")) height = "" + json.getInt("height"); if (json.has("text")) text = json.getString("text"); if (json.has("value")) valueString = json.getString("value"); } catch (JSONException e) { e.printStackTrace(); } // // {"imageUrl":"http:\/\/streetlearn.appspot.com\/\/uploadService\/2288002\/2:113116978440346588314\/image1537716519.jpg","width":3264,"height":1840} // {"answer":"3","isCorrect":true} csv += responseJDO.getResponseId() + ";" + responseJDO.getTimestamp() + ";" + responseJDO.getGeneralItemId() + ";" + responseJDO.getResponseItemId() + ";" + responseJDO.getUserEmail() + ";" + imageUrl + ";" + videoUrl + ";" + width + ";" + height + ";" + lat + ";" + lng + ";" + audioUrl + ";" + text + ";" + valueString + "\n"; } entry.setCSV(csv); return entry; }