Exemplo n.º 1
0
  /**
   * Parses error response.
   *
   * @param response parsed <tt>ErrorResponse</tt>
   * @return <tt>ErrorResponse</tt> parsed from HTTP content stream.
   * @throws IOException if any IO issues occur.
   * @throws ParseException if any issues with JSON parsing occur.
   */
  private ErrorResponse readErrorResponse(HttpResponse response)
      throws IOException, ParseException {
    BufferedReader rd =
        new BufferedReader(new InputStreamReader(response.getEntity().getContent()));

    jsonParser.parse(rd, errorJson);

    return errorJson.getResult();
  }
Exemplo n.º 2
0
  /**
   * Parses JSON string returned in HTTP response and converts it to <tt>Conference</tt> instance.
   *
   * @param conference <tt>Conference</tt> instance that contains the data returned by API endpoint.
   * @param response HTTP response returned by the API endpoint.
   * @return <tt>Conference</tt> instance that contains the data returned by API endpoint.
   * @throws IOException if any IO problems occur.
   * @throws ParseException if any problems with JSON parsing occur.
   */
  private Conference readConferenceResponse(Conference conference, HttpResponse response)
      throws IOException, ParseException {
    BufferedReader rd =
        new BufferedReader(new InputStreamReader(response.getEntity().getContent()));

    if (conference != null) {
      conferenceJson.setForUpdate(conference);
    }

    jsonParser.parse(rd, conferenceJson);

    if (conference == null) {
      conference = conferenceJson.getResult();
    }

    logger.info("ID: " + conference.getId());
    logger.info("PIN: " + conference.getPin());
    logger.info("URL: " + conference.getUrl());
    logger.info("SIP ID: " + conference.getSipId());
    logger.info("START TIME: " + conference.getStartTime());
    logger.info("DURATION: " + conference.getDuration());

    return conference;
  }
Exemplo n.º 3
0
  public Map getTaskMapBatch(String objectId) throws Exception {

    Map map = new HashMap();

    String apiURL = "https://rally1.rallydev.com/slm/webservice/1.34/adhoc";

    String requestJSON =
        "{"
            + "\"task\" : \"/task?query=(ObjectID%20=%20"
            + objectId
            + ")&fetch=true\","
            + "\"userstory\" : \"/hierarchicalrequirement?query=(ObjectID%20=%20${task.WorkProduct.ObjectID})&fetch=FormattedID\","
            + "\"timeentryitem\":\"/timeentryitem?query=(Task.ObjectID%20=%20"
            + objectId
            + ")&fetch=Values\","
            + "\"timespent\":\"${timeentryitem.Values.Hours}\""
            + "}";

    log.info("apiURL=" + apiURL);
    log.info("requestJSON=" + requestJSON);

    String responseJSON = postRallyXML(apiURL, requestJSON);

    // log.info("responseJSON="+responseJSON);

    // Map jsonMap=JsonUtil.jsonToMap(responseJSON);
    JSONParser parser = new JSONParser();
    Map jsonMap = (Map) parser.parse(responseJSON);

    // log.info("jsonMap="+jsonMap);

    String taskObjId = "";
    String taskFormattedId = "";
    String taskName = "";
    String estimate = "";
    String toDo = "";
    String taskState = "";
    String taskOwner = "";
    String userstoryFormattedId = "";

    // Get task info
    JSONObject taskMap = (JSONObject) jsonMap.get("task");
    JSONArray taskArray = (JSONArray) taskMap.get("Results");
    if (taskArray != null && taskArray.size() > 0) {
      JSONObject taskInfo = (JSONObject) taskArray.get(0);
      // log.info("taskMap="+taskMap);
      // log.info("taskInfo="+taskInfo);

      taskObjId = (taskInfo.get("ObjectID")).toString();
      taskFormattedId = (taskInfo.get("FormattedID")).toString();
      taskState = (taskInfo.get("State")).toString();

      Object taskNameObj = taskInfo.get("Name");
      taskName = taskNameObj == null ? "" : taskNameObj.toString();

      Object estimateObject = taskInfo.get("Estimate");
      estimate = estimateObject == null ? "" : estimateObject.toString();

      Object toDoObject = taskInfo.get("ToDo");
      toDo = toDoObject == null ? "" : toDoObject.toString();

      JSONObject ownerMap = (JSONObject) taskInfo.get("Owner");
      log.info("ownerMap=" + ownerMap);
      if (ownerMap != null) {
        taskOwner = (String) ownerMap.get("_refObjectName");
        if (taskOwner == null) {
          taskOwner = "";
        }
      }
    }

    // Get user story info
    JSONObject userstoryMap = (JSONObject) jsonMap.get("userstory");
    JSONArray userstoryArray = (JSONArray) userstoryMap.get("Results");
    if (userstoryArray != null && userstoryArray.size() > 0) {
      JSONObject userstoryInfo = (JSONObject) userstoryArray.get(0);

      userstoryFormattedId = (userstoryInfo.get("FormattedID")).toString();
      log.info("userstoryFormattedId=" + userstoryFormattedId);
    }

    // Calculate timeSpent
    JSONArray timeSpentList = (JSONArray) jsonMap.get("timespent");
    log.info("timeSpentList=" + timeSpentList);

    double timeSpent = 0.0;
    for (int i = 0; i < timeSpentList.size(); i++) {
      String timeSpentString = (String) timeSpentList.get(i);

      if (timeSpentString != null) {
        timeSpent += Double.parseDouble(timeSpentString);
      }
    }

    map.put("type", "task");
    map.put("formattedId", taskFormattedId);
    map.put("usId", userstoryFormattedId);
    map.put("name", taskName);
    map.put("taskStatus", taskState);
    map.put("owner", taskOwner);
    map.put("taskEstimateTotal", estimate);
    map.put("taskRemainingTotal", toDo);
    map.put("taskTimeSpentTotal", "" + timeSpent);

    return map;
  }
Exemplo n.º 4
0
  public double getTimeSpentByTask(String taskNo) throws Exception {

    double timeSpent = 0.0D;

    String apiURL = "https://rally1.rallydev.com/slm/webservice/1.34/adhoc";

    String requestJSON =
        "{"
            + "\"task\" : \"/task?query=(FormattedID%20=%20"
            + taskNo
            + ")&fetch=true\","
            + "\"timeentryitem\":\"/timeentryitem?query=(Task.FormattedID%20=%20"
            + taskNo
            + ")&fetch=Values\","
            + "\"timespent\":\"${timeentryitem.Values.Hours}\""
            + "}";

    log.info("apiURL=" + apiURL);
    log.info("requestJSON=" + requestJSON);

    String responseJSON = postRallyXML(apiURL, requestJSON);

    // log.info("responseJSON="+responseJSON);

    // Map jsonMap=JsonUtil.jsonToMap(responseJSON);
    JSONParser parser = new JSONParser();
    Map jsonMap = (Map) parser.parse(responseJSON);

    /*
    //log.info("jsonMap="+jsonMap);

    String taskObjId="";
    String taskFormattedId="";
    String taskName="";
    String estimate="";
    String toDo="";
    String taskState="";
    String taskOwner="";
    String userstoryFormattedId="";

    //Get task info
    JSONObject taskMap=(JSONObject)jsonMap.get("task");
    JSONArray taskArray=(JSONArray)taskMap.get("Results");
    if(taskArray!=null && taskArray.size()>0) {
    	JSONObject taskInfo=(JSONObject)taskArray.get(0);
    	//log.info("taskMap="+taskMap);
    	//log.info("taskInfo="+taskInfo);

    	taskObjId=(taskInfo.get("ObjectID")).toString();
    	taskFormattedId=(taskInfo.get("FormattedID")).toString();
    	taskState=(taskInfo.get("State")).toString();

    	Object taskNameObj=taskInfo.get("Name");
    	taskName=taskNameObj==null ? "" : taskNameObj.toString();

    	Object estimateObject=taskInfo.get("Estimate");
    	estimate=estimateObject==null ? "" : estimateObject.toString();

    	Object toDoObject=taskInfo.get("ToDo");
    	toDo=toDoObject==null ? "" : toDoObject.toString();

    	JSONObject ownerMap=(JSONObject)taskInfo.get("Owner");
    	log.info("ownerMap="+ownerMap);
    	if(ownerMap!=null) {
    		taskOwner=(String)ownerMap.get("_refObjectName");
    		if(taskOwner==null) {
    			taskOwner="";
    		}
    	}
    }

    //Get user story info
    JSONObject userstoryMap=(JSONObject)jsonMap.get("userstory");
    JSONArray userstoryArray=(JSONArray)userstoryMap.get("Results");
    if(userstoryArray!=null && userstoryArray.size()>0) {
    	JSONObject userstoryInfo=(JSONObject)userstoryArray.get(0);

    	userstoryFormattedId=(userstoryInfo.get("FormattedID")).toString();
    	log.info("userstoryFormattedId="+userstoryFormattedId);
    }
    */

    // Calculate timeSpent
    JSONArray timeSpentList = (JSONArray) jsonMap.get("timespent");
    log.info("timeSpentList=" + timeSpentList);

    // double timeSpent=0.0;
    for (int i = 0; i < timeSpentList.size(); i++) {
      String timeSpentString = (String) timeSpentList.get(i);

      if (timeSpentString != null) {
        timeSpent += Double.parseDouble(timeSpentString);
      }
    }

    return timeSpent;
  }