public void registrarUsuario() { String dato = ""; JSONParser parser = new JSONParser(); try { while (true) { dato = dis.readUTF(); String usuario = ""; String contraseña = ""; String contra = ""; if (dato.equals("Usuario")) { while (true) { usuario = dis.readUTF(); if (usuario != null) { JSONObject user = new JSONObject(); user.put(usuario, null); FileWriter escribir = new FileWriter("texto.txt"); BufferedWriter bw = new BufferedWriter(escribir); PrintWriter pw = new PrintWriter(bw); pw.write(user.toJSONString()); pw.close(); bw.close(); while (true) { contra = dis.readUTF(); if (contra.equals("Contraseña")) { while (true) { contraseña = dis.readUTF(); if (contraseña != null) { Object obj = parser.parse(new FileReader("texto.txt")); JSONObject asignaPass = (JSONObject) obj; asignaPass.put(usuario, contra); FileWriter escribir2 = new FileWriter("texto.txt"); BufferedWriter bw2 = new BufferedWriter(escribir2); PrintWriter pw2 = new PrintWriter(bw2); pw2.write(asignaPass.toJSONString()); bw2.newLine(); pw2.close(); bw2.close(); break; } } break; } } break; } } break; } } } catch (Exception e) { } }
/** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ @SuppressWarnings("unchecked") protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("application/json"); response.setHeader("Cache-Control", "nocache"); response.setCharacterEncoding("utf-8"); PrintWriter out = response.getWriter(); StringWriter result = new StringWriter(); // get received JSON data from request BufferedReader br = new BufferedReader(new InputStreamReader(request.getInputStream())); String postData = ""; if (br != null) { postData = br.readLine(); } try { JSONObject json = (JSONObject) new JSONParser().parse(postData); JSONObject resultObj = new JSONObject(); JSONArray list = new JSONArray(); List<Tracking> trackingList = new ArrayList<Tracking>(); // get the website list if (json.get("type").equals("websiteslist")) { trackingList = trackingDao.websiteList(pool); for (Tracking item : trackingList) { list.add(item.getWebsite()); } } // render report else if (json.get("type").equals("submit")) { if (json.get("criteria").equals("date")) { // render repoty by date trackingList = trackingDao.getListByDate(pool, json.get("date").toString()); } else if (json.get("criteria").equals("daterange")) { // render repoty by date range trackingList = trackingDao.getListByDateRange( pool, json.get("fromdate").toString(), json.get("todate").toString()); } else if (json.get("criteria").equals("website")) { // render repoty by website String website = (json.get("website") == null ? "" : json.get("website").toString()); trackingList = trackingDao.getListByWebsite(pool, website); } for (Tracking item : trackingList) { JSONObject trackingObj = new JSONObject(); trackingObj.put("date", item.getDate()); trackingObj.put("website", item.getWebsite()); trackingObj.put("visit", item.getVisit()); list.add(trackingObj); } } resultObj.put("result", list); resultObj.writeJSONString(result); // finally output the json string out.print(result.toString()); } catch (ParseException | SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
// 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; }