public StringBuilder listToCSV(List list) { StringBuilder csv = new StringBuilder(); csv.append( "Work Product,,Name,State,Owner,Plan Estimate,Task Estimate,Task Remaining,Time Spent\n"); for (int i = 0; i < list.size(); i++) { Map map = (Map) list.get(i); String type = (String) map.get("type"); String formattedId = (String) map.get("formattedId"); String name = (String) map.get("name"); String taskStatus = (String) map.get("taskStatus"); String owner = (String) map.get("owner"); String planEstimate = (String) map.get("planEstimate"); String taskEstimateTotal = (String) map.get("taskEstimateTotal"); String taskRemainingTotal = (String) map.get("taskRemainingTotal"); String taskTimeSpentTotal = (String) map.get("taskTimeSpentTotal"); if ("task".equals(type)) { csv.append("," + formattedId + ","); } else if ("userstory".equals(type)) { csv.append(formattedId + ",,"); } else if ("iteration".equals(type)) { csv.append(",,"); } if (planEstimate == null) { planEstimate = ""; } if (taskEstimateTotal == null) { taskEstimateTotal = ""; } if (taskRemainingTotal == null) { taskRemainingTotal = ""; } csv.append("\"" + name + "\","); csv.append(taskStatus + ","); csv.append(owner + ","); csv.append(planEstimate + ","); csv.append(taskEstimateTotal + ","); csv.append(taskRemainingTotal + ","); csv.append(taskTimeSpentTotal + "\n"); } return csv; }
public StringBuilder listToCSVForUserView(List list) { StringBuilder csv = new StringBuilder(); csv.append( "Project,Iteration,Work Product,Name,State,Owner,Task Estimate,Task Remaining,Time Spent\n"); for (int i = 0; i < list.size(); i++) { Map map = (Map) list.get(i); String projectName = (String) map.get("projectName"); String iterationName = (String) map.get("iterationName"); String formattedId = (String) map.get("taskFormattedId"); String taskName = (String) map.get("taskName"); String taskState = (String) map.get("taskState"); String owner = (String) map.get("owner"); String taskEstimate = (String) map.get("taskEstimate"); String taskRemaining = (String) map.get("taskRemaining"); String taskTimeSpent = (String) map.get("hours"); if (taskEstimate == null) { taskEstimate = ""; } if (taskRemaining == null) { taskRemaining = ""; } csv.append("" + projectName + ","); csv.append("\"" + iterationName + "\","); csv.append(formattedId + ","); csv.append(taskName + ","); csv.append(taskState + ","); csv.append(owner + ","); csv.append(taskEstimate + ","); csv.append(taskRemaining + ","); csv.append(taskTimeSpent + "\n"); } return csv; }
// public List getUserStoryList(String sessionId,String iterationId,ServletOutputStream out) { public List getUserStoryList(String sessionId, String iterationId, PrintWriter out) { List<Map> list = new ArrayList<Map>(); statusMap.put(sessionId, "0"); try { String apiURL = rallyApiHost + "/hierarchicalrequirement?" + "query=(Iteration%20=%20" + rallyApiHost + "/iteration/" + iterationId + ")&fetch=true&start=1&pagesize=100"; log.info("getUserStoryList apiURL=" + apiURL); String responseXML = getRallyXML(apiURL); org.jdom.input.SAXBuilder bSAX = new org.jdom.input.SAXBuilder(); org.jdom.Document doc = bSAX.build(new StringReader(responseXML)); Element root = doc.getRootElement(); XPath xpath = XPath.newInstance("//Object"); List xlist = xpath.selectNodes(root); int totalSteps = xlist.size() + 1; int currentStep = 0; List taskRefLink = new ArrayList(); Iterator iter = xlist.iterator(); while (iter.hasNext()) { double totalTimeSpent = 0.0D; Map map = new HashMap(); Element item = (Element) iter.next(); String objId = item.getChildText("ObjectID"); String name = item.getChildText("Name"); String planEstimate = item.getChildText("PlanEstimate"); String formattedId = item.getChildText("FormattedID"); String taskActualTotal = item.getChildText("TaskActualTotal"); String taskEstimateTotal = item.getChildText("TaskEstimateTotal"); String taskRemainingTotal = item.getChildText("TaskRemainingTotal"); String scheduleState = item.getChildText("ScheduleState"); Element ownerElement = item.getChild("Owner"); String owner = ""; String ownerRef = ""; if (ownerElement != null) { owner = ownerElement.getAttributeValue("refObjectName"); } Element taskElements = item.getChild("Tasks"); // List taskElementList=taskElements.getContent(); List taskElementList = taskElements.getChildren(); List taskList = new ArrayList(); log.info("taskElements.getChildren=" + taskElements); log.info("taskList=" + taskElementList); for (int i = 0; i < taskElementList.size(); i++) { Element taskElement = (Element) taskElementList.get(i); String taskRef = taskElement.getAttributeValue("ref"); String[] objectIdArr = taskRef.split("/"); String objectId = objectIdArr[objectIdArr.length - 1]; log.info("objectId=" + objectId); // Map taskMap=getTaskMap(taskRef); Map taskMap = getTaskMapBatch(objectId); double taskTimeSpentTotal = Double.parseDouble((String) taskMap.get("taskTimeSpentTotal")); totalTimeSpent += taskTimeSpentTotal; taskList.add(taskMap); } map.put("type", "userstory"); map.put("formattedId", formattedId); map.put("name", name); map.put("taskStatus", scheduleState); map.put("owner", owner); map.put("planEstimate", planEstimate); map.put("taskEstimateTotal", taskEstimateTotal); map.put("taskRemainingTotal", taskRemainingTotal); map.put("taskTimeSpentTotal", "" + totalTimeSpent); list.add(map); list.addAll(taskList); ++currentStep; double percentage = 100.0D * currentStep / totalSteps; String status = "" + Math.round(percentage); statusMap.put(sessionId, status); out.println("<script>parent.updateProcessStatus('" + status + "%')</script>" + status); out.flush(); log.info("out.flush..." + status); // log.info("status="+status+" sessionId="+sessionId); // log.info("L1 statusMap="+statusMap+" "+statusMap.hashCode()); } double planEstimate = 0.0D; double taskEstimateTotal = 0.0D; double taskRemainingTotal = 0.0D; double taskTimeSpentTotal = 0.0D; Map iterationMap = new HashMap(); for (Map map : list) { String type = (String) map.get("type"); String planEstimateStr = (String) map.get("planEstimate"); log.info("planEstimateStr=" + planEstimateStr); if ("userstory".equals(type)) { if (planEstimateStr != null) { planEstimate += Double.parseDouble(planEstimateStr); } taskEstimateTotal += Double.parseDouble((String) map.get("taskEstimateTotal")); taskRemainingTotal += Double.parseDouble((String) map.get("taskRemainingTotal")); taskTimeSpentTotal += Double.parseDouble((String) map.get("taskTimeSpentTotal")); } } apiURL = rallyApiHost + "/iteration/" + iterationId + "?fetch=true"; log.info("iteration apiURL=" + apiURL); responseXML = getRallyXML(apiURL); bSAX = new org.jdom.input.SAXBuilder(); doc = bSAX.build(new StringReader(responseXML)); root = doc.getRootElement(); xpath = XPath.newInstance("//Iteration"); xlist = xpath.selectNodes(root); String projName = ""; String iterName = ""; String iterState = ""; iter = xlist.iterator(); while (iter.hasNext()) { Element item = (Element) iter.next(); iterName = item.getChildText("Name"); iterState = item.getChildText("State"); Element projElement = item.getChild("Project"); projName = projElement.getAttributeValue("refObjectName"); } iterationMap.put("type", "iteration"); iterationMap.put("formattedId", ""); iterationMap.put("name", projName + " - " + iterName); iterationMap.put("taskStatus", iterState); iterationMap.put("owner", ""); iterationMap.put("planEstimate", "" + planEstimate); iterationMap.put("taskEstimateTotal", "" + taskEstimateTotal); iterationMap.put("taskRemainingTotal", "" + taskRemainingTotal); iterationMap.put("taskTimeSpentTotal", "" + taskTimeSpentTotal); list.add(0, iterationMap); statusMap.put(sessionId, "100"); log.info("L2 statusMap=" + statusMap); log.info("L2 verify=" + getProcessStatus(sessionId)); log.info("-----------"); // String jsonData=JsonUtil.encodeObj(list); String jsonData = JSONValue.toJSONString(list); out.println("<script>parent.tableResult=" + jsonData + "</script>"); out.println("<script>parent.showTableResult()</script>"); } catch (Exception ex) { log.error("ERROR: ", ex); } return list; }
public List getUserTimeSpentByDate(String userObjectId, String startDate, String endDate) { List list = new ArrayList(); log.info("userObjectId=" + userObjectId); log.info("startDate=" + startDate); log.info("endDate=" + endDate); try { String apiUrl = rallyApiHost + "/timeentryvalue?query=((TimeEntryItem.User.ObjectId%20=%20" + userObjectId + ")" + "%20and%20((DateVal%20%3E=%20" + startDate + ")%20and%20(DateVal%20%3C=%20" + endDate + ")))" + "&start=1&pagesize=100&fetch=true"; log.info("apiUrl=" + apiUrl); String responseXML = getRallyXML(apiUrl); log.info("responseXML=" + responseXML); org.jdom.input.SAXBuilder bSAX = new org.jdom.input.SAXBuilder(); org.jdom.Document doc = bSAX.build(new StringReader(responseXML)); Element root = doc.getRootElement(); XPath xpath = XPath.newInstance("//Object"); List xlist = xpath.selectNodes(root); Iterator iter = xlist.iterator(); while (iter.hasNext()) { // Map map=new HashMap(); Element item = (Element) iter.next(); String hours = item.getChildText("Hours"); Element timeEntryItemElement = item.getChild("TimeEntryItem"); String timeEntryItemRef = timeEntryItemElement.getAttributeValue("ref"); Map map = getUserStoryTaskMap(timeEntryItemRef); String checkTaskId = (String) map.get("taskFormattedId"); boolean isExist = false; for (int i = 0; i < list.size(); i++) { Map existMap = (Map) list.get(i); log.info("existMap=" + existMap); String existTaskId = (String) existMap.get("taskFormattedId"); log.info("existTaskId=" + existTaskId); log.info("checkTaskId=" + checkTaskId); if (existTaskId != null && existTaskId.equals(checkTaskId)) { isExist = true; String existHours = (String) existMap.get("hours"); double eHour = 0.0D; if (!"".equals(existHours)) { eHour = Double.parseDouble(existHours); } double nHour = 0.0D; if (!"".equals(hours)) { nHour = Double.parseDouble(hours); } log.info("nHour=" + nHour); log.info("eHour=" + eHour); nHour += eHour; log.info("2 nHour=" + nHour); existMap.put("hours", "" + nHour); break; } } if (!isExist) { map.put("hours", hours); list.add(map); } log.info("hours=" + hours); log.info("timeEntryItemRef=" + timeEntryItemRef); // list.add(map); } Collections.sort( list, new Comparator<Map<String, String>>() { public int compare(Map<String, String> m1, Map<String, String> m2) { if (m1.get("projectName") == null || m2.get("projectName") == null) return -1; return m1.get("projectName").compareTo(m2.get("projectName")); } }); // Sum up the total time double totalTaskEstimate = 0.0D; double totalTaskRemaining = 0.0D; double totalHours = 0.0D; for (int i = 0; i < list.size(); i++) { Map map = (Map) list.get(i); log.info("taskEstimate=" + (String) map.get("taskEstimate")); log.info("taskRemaining=" + (String) map.get("taskRemaining")); log.info("hours=" + (String) map.get("hours")); log.info("map==" + map); try { double taskEstimate = Double.parseDouble((String) map.get("taskEstimate")); double taskRemaining = Double.parseDouble((String) map.get("taskRemaining")); double hours = Double.parseDouble((String) map.get("hours")); totalTaskEstimate += taskEstimate; totalTaskRemaining += taskRemaining; totalHours += hours; } catch (Exception e) { log.info("ERROR in parsing number" + e); } } Map firstMap = new HashMap(); firstMap.put("taskFormattedId", ""); firstMap.put("taskName", ""); firstMap.put("taskState", ""); firstMap.put("owner", ""); firstMap.put("taskEstimate", "" + totalTaskEstimate); firstMap.put("taskRemaining", "" + totalTaskRemaining); firstMap.put("hours", "" + totalHours); firstMap.put("projectName", ""); firstMap.put("iterationName", ""); list.add(0, firstMap); } catch (Exception ex) { log.error("", ex); } return list; }
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { JSONParser parser = new JSONParser(); String originalRouteJsonString = request.getParameter("originalroutejsontext"); JSONObject originalRouteJsonObject = (JSONObject) parser.parse(originalRouteJsonString); JSONObject routes = (JSONObject) ((JSONArray) originalRouteJsonObject.get("routes")).get(0); JSONArray legs = (JSONArray) routes.get("legs"); JSONArray steps = (JSONArray) ((JSONObject) legs.get(0)).get("steps"); String routeID = request.getParameter("routeid"); // System.out.println("Route steps loaded in a JSONArray...size is " + steps.size()); List<Double> stepLats = new ArrayList<Double>(); List<Double> stepLngs = new ArrayList<Double>(); for (int i = 0; i < steps.size(); i++) { JSONObject temp = (JSONObject) ((JSONObject) steps.get(i)).get("end_location"); // System.out.println("Lat of end_location of step " + i + " " + temp.get("lat")); stepLats.add(Double.parseDouble(temp.get("lat").toString())); stepLngs.add(Double.parseDouble(temp.get("lng").toString())); } // System.out.println("All steps set with size " + stepLngs.size() + " and " + // stepLats.size()); // System.out.println("Skipping route boxer..."); // RouteBoxer routeBoxer = new RouteBoxer(stepLats, stepLngs, // Double.parseDouble(request.getParameter("radius"))); // if(routeBoxer.getFlag()) // throw new RuntimeException("Could not create boxes for the route"); // List<Double> boxLats = routeBoxer.getLats(); // List<Double> boxLngs = routeBoxer.getLngs(); // System.out.println("Calculated boxes with number of lats " + boxLats.size() + " and number // of lngs " + boxLngs.size()); double r = Double.parseDouble(request.getParameter("radius").toString()); int radius = r > RADIUS_TO_LOOK_FOR_PLACES ? RADIUS_TO_LOOK_FOR_PLACES : (int) r; String[] types = request.getParameter("keywords").split(","); System.out.println("Size of types is " + types.length); JSONObject finalPlacesJSONObject = new JSONObject(); for (int j = 0; j < types.length; j++) { JSONArray jsonArrayForType = new JSONArray(); for (int i = 0; i < stepLats.size(); i++) { JSONObject placesAroundLocationJSONObject = (JSONObject) parser.parse( GoogleMap.getPlacesAroundLocation( stepLats.get(i), stepLngs.get(i), radius, types[j])); JSONArray placesAroundLocationJSONArray = (JSONArray) placesAroundLocationJSONObject.get("results"); if (!placesAroundLocationJSONArray.isEmpty()) { jsonArrayForType.addAll(placesAroundLocationJSONArray); } } finalPlacesJSONObject.put(types[j], jsonArrayForType); } List<String> place_ids = new ArrayList<String>(); finalPlacesJSONObject = removeDuplicatePlaces(finalPlacesJSONObject); finalPlacesJSONObject = filterPlacesRandomly(finalPlacesJSONObject, FINAL_PLACES_NUMBER_PER_REQUEST, place_ids); // System.out.println("MAGIC " + place_ids.toString()); DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); MemcacheService syncCache = MemcacheServiceFactory.getMemcacheService(); // add places as a property of original route entity Entity originalRouteEntity = datastore.get(KeyFactory.createKey("Route", Long.parseLong(routeID))); Text placesJsonAsText = new Text(finalPlacesJSONObject.toJSONString()); originalRouteEntity.setProperty("placesJSON", placesJsonAsText); datastore.put(originalRouteEntity); // System.out.println("SUCCESS written places to datastore"); // add task for fetching place reviews to queue QueueFactory.getDefaultQueue() .add( TaskOptions.Builder.withUrl("/waypointsreview") .param("places", place_ids.toString())); System.out.println("Task to get reviews added to queue"); // We cache the route entity String cacheKey = "route-" + routeID; syncCache.put(cacheKey, originalRouteEntity); } catch (Exception e) { System.out.println("ERROR " + e.getMessage()); e.printStackTrace(); } }