public static void main(String[] args) throws URISyntaxException, IOException {

    String host = "https://rally1.rallydev.com";
    String apiKey = "_abc123"; // use your ApiKey
    String applicationName = "Nick:PiTypes";

    RallyRestApi restApi = new RallyRestApi(new URI(host), apiKey);
    restApi.setApplicationName(applicationName);
    String workspaceRef = "/workspace/12345";

    try {
      QueryRequest typedefRequest = new QueryRequest("TypeDefinition");
      typedefRequest.setFetch(new Fetch("ElementName", "Ordinal"));
      typedefRequest.setOrder("Ordinal DESC");
      typedefRequest.setQueryFilter(new QueryFilter("Parent.Name", "=", "Portfolio Item"));
      typedefRequest.setWorkspace(workspaceRef);
      QueryResponse typedefResponse = restApi.query(typedefRequest);
      for (int i = 0; i < typedefResponse.getTotalResultCount(); i++) {
        JsonObject typedefObj = typedefResponse.getResults().get(i).getAsJsonObject();
        if (typedefObj.get("Ordinal").getAsInt() > -1) {
          System.out.println(
              "ElementName: "
                  + typedefObj.get("ElementName")
                  + ", "
                  + "Ordinal: "
                  + typedefObj.get("Ordinal"));
        }
      }
    } finally {
      restApi.close();
    }
  }
Пример #2
0
  private StoryList retrieveStoriesByQuery(QueryFilter filter)
      throws IOException, ConnectorException, TransformerException, URISyntaxException {
    RallyRestApi restApi = new RallyRestApi(new URI(RALLY_SERVER_URL), username, password);

    QueryRequest storyQuery = new QueryRequest("HierarchicalRequirement");
    QueryRequest defectQuery = new QueryRequest("Defect");

    StoryList stories = objFactory.createStoryList();

    try {
      defectQuery.setQueryFilter(filter);
      storyQuery.setQueryFilter(filter);

      QueryResponse storyResp = restApi.query(storyQuery);
      QueryResponse defectResp = restApi.query(defectQuery);

      if (storyResp.wasSuccessful()) {
        List<StoryType> storyList = getStoryList(storyResp.getResults());
        stories.getStory().addAll(storyList);
      }

      if (defectResp.wasSuccessful()) {
        List<StoryType> defectList = getStoryList(defectResp.getResults());
        stories.getStory().addAll(defectList);
      }
    } finally {
      restApi.close();
    }
    return stories;
  }
Пример #3
0
  @Override
  public TaskList retrieveTasks(StoryList stories)
      throws IOException, ClientProtocolException, ConnectorException, TransformerException,
          URISyntaxException {
    RallyRestApi restApi = new RallyRestApi(new URI(RALLY_SERVER_URL), username, password);
    QueryRequest taskQuery = new QueryRequest("Task");

    TaskList taskList = objFactory.createTaskList();
    try {
      for (StoryType story : stories.getStory()) {
        String storyID = story.getIdentifier();
        Link storyLink = findLinkByRel(story, RALLY_OBJECT_URL_REL);
        if (storyLink != null) {
          storyLink.setRel(RALLY_PARENT_URL_REL);
        }

        NDC.push("retrieving tasks for " + storyID);
        logger.debug(NDC.peek());
        QueryFilter filter = new QueryFilter("WorkProduct.FormattedID", "=", storyID);
        taskQuery.setQueryFilter(filter);
        QueryResponse query = restApi.query(taskQuery);
        if (query.wasSuccessful()) {
          for (JsonElement e : query.getResults()) {
            if (e == null) continue;
            TaskType task = objFactory.createTaskType();
            JsonObject jsonTask = e.getAsJsonObject();
            String taskName = jsonTask.get("Name").getAsString();

            task.setParentIdentifier(storyID);
            task.setDescription(fixDescription(getValueOrDefault(jsonTask.get("Description"), "")));
            if (!jsonTask.get("Owner").isJsonNull()) {
              task.setOwner(
                  getValueOrDefault(
                      jsonTask.get("Owner").getAsJsonObject().get("_refObjectName"), ""));
            }
            task.setFullName(taskName);
            task.setShortName((taskName.length() > 30) ? taskName.substring(0, 30) : taskName);
            task.setIdentifier(jsonTask.get("FormattedID").getAsString());
            task.setDetailedEstimate(getValueOrDefault(jsonTask.get("Estimate"), new Double(0.0)));
            task.setTodoRemaining(getValueOrDefault(jsonTask.get("Estimate"), new Double(0.0)));
            task.setEffortApplied(getValueOrDefault(jsonTask.get("Actuals"), new Double(0.0)));
            task.setDescription(fixDescription(getValueOrDefault(jsonTask.get("Description"), "")));
            addLink(story, jsonTask.get("_ref").getAsString(), RALLY_OBJECT_URL_REL);

            addLink(task, jsonTask.get("_ref").getAsString(), RALLY_OBJECT_URL_REL);
            addLink(task, storyLink);
            taskList.getTask().add(task);
          }
        }
      }
    } finally {
      NDC.pop();
      restApi.close();
    }
    return taskList;
  }
  public static void main(String[] args) throws URISyntaxException, IOException {

    // Create and configure a new instance of RallyRestApi
    // (Server, username, password and proxy settings configured in Factory)
    RallyRestApi restApi = RestApiFactory.getRestApi();

    try {
      String ref = "/hierarchicalrequirement/12544729477";
      GetRequest getRequest = new GetRequest(ref);
      getRequest.setFetch(new Fetch("Defects"));

      System.out.println(String.format("\nReading defect info for story %s...", ref));
      GetResponse getResponse = restApi.get(getRequest);
      JsonObject story = getResponse.getObject();

      JsonObject defectInfo = story.getAsJsonObject("Defects");
      int defectCount = defectInfo.get("Count").getAsInt();
      System.out.println(String.format("\nTotal defects: %d", defectCount));

      if (defectCount > 0) {
        QueryRequest defectRequest = new QueryRequest(defectInfo);
        defectRequest.setFetch(new Fetch("FormattedID", "Name", "State", "Priority"));

        QueryResponse queryResponse = restApi.query(defectRequest);
        if (queryResponse.wasSuccessful()) {
          for (JsonElement result : queryResponse.getResults()) {
            JsonObject defect = result.getAsJsonObject();
            System.out.println(
                String.format(
                    "\t%s - %s: Priority=%s, State=%s",
                    defect.get("FormattedID").getAsString(),
                    defect.get("Name").getAsString(),
                    defect.get("Priority").getAsString(),
                    defect.get("State").getAsString()));
          }
        }
      }
    } finally {
      // Release resources
      restApi.close();
    }
  }
Пример #5
0
  @Override
  public List<IterationStatus> listIterationsForProject(String projectName)
      throws IOException, ConnectorException, URISyntaxException {
    List<IterationStatus> iterationList = new ArrayList<IterationStatus>();
    RallyRestApi restApi = new RallyRestApi(new URI(RALLY_SERVER_URL), username, password);

    QueryRequest query = new QueryRequest("Iterations");

    query.setFetch(new Fetch("Name"));
    query.setQueryFilter(new QueryFilter("Project.Name", "=", "Adrenalin SeaDAC Renderer"));

    QueryResponse resp = restApi.query(query);

    for (JsonElement r : resp.getResults()) {
      JsonObject result = r.getAsJsonObject();
      iterationList.add(
          new IterationStatus(
              result.get("Name").getAsString(), new URI(result.get("_ref").getAsString())));
    }

    restApi.close();
    return iterationList;
  }
Пример #6
0
  public static void test1() throws URISyntaxException, IOException {
    User user = User.getInstance();
    // Create and configure a new instance of RallyRestApi
    RallyRestApi restApi =
        new RallyRestApi(
            new URI("https://rally1.rallydev.com"), user.getUser(), user.getPassword());
    restApi.setApplicationName("QueryExample");

    try {

      System.out.println("Querying for unaccepted stories for current user...");

      QueryRequest defects = new QueryRequest("HierarchicalRequirement");

      defects.setFetch(new Fetch("FormattedID", "Name", "ScheduleState"));
      QueryFilter qf1 = new QueryFilter("Owner.Name", "=", user.getUser());
      QueryFilter qf2 = new QueryFilter("ScheduleState", "<", "Accepted");
      defects.setQueryFilter(qf1.and(qf2));
      defects.setOrder("FormattedID DESC");

      // Return up to 20, 1 per page
      defects.setPageSize(1);
      defects.setLimit(20);

      QueryResponse queryResponse = restApi.query(defects);
      if (queryResponse.wasSuccessful()) {
        System.out.println(
            String.format("\nTotal results: %d", queryResponse.getTotalResultCount()));
        System.out.println("unaccept stories:");
        for (JsonElement result : queryResponse.getResults()) {
          JsonObject defect = result.getAsJsonObject();
          System.out.println(
              String.format(
                  "\t%s - %s - ScheduleState:%s",
                  defect.get("FormattedID").getAsString(),
                  defect.get("Name").getAsString(),
                  defect.get("ScheduleState").getAsString()));
        }
      } else {
        System.err.println("The following errors occurred: ");
        for (String err : queryResponse.getErrors()) {
          System.err.println("\t" + err);
        }
      }

    } finally {
      // Release resources
      restApi.close();
    }
  }
  public static void main(String[] args) throws URISyntaxException, IOException {

    String host = "https://rally1.rallydev.com";
    String apiKey = "_abc123";
    String workspaceRef = "/workspace/12352608129";
    String applicationName = "bulkUpdateTagsOnDefects";

    RallyRestApi restApi = new RallyRestApi(new URI(host), apiKey);
    restApi.setApplicationName(applicationName);

    try {
      String tagToRemove = "tag1";
      String tagToAdd = "new tag";

      // find all defects with "tag1" with ScheduleState < Completed
      QueryRequest defectRequest = new QueryRequest("Defect");
      defectRequest.setWorkspace(workspaceRef);
      defectRequest.setFetch(new Fetch(new String[] {"Name", "FormattedID", "Tags"}));
      defectRequest.setLimit(1000);

      defectRequest.setQueryFilter(
          (new QueryFilter("Tags.Name", "contains", tagToRemove))
              .and(new QueryFilter("ScheduleState", "<", "Completed")));

      QueryResponse defectQueryResponse = restApi.query(defectRequest);
      System.out.println("Size: " + defectQueryResponse.getTotalResultCount());

      /*
      QueryRequest  oldTagRequest = new QueryRequest("Tag");
      oldTagRequest.setWorkspace(workspaceRef);
      oldTagRequest.setQueryFilter(new QueryFilter("Name", "=", tagToRemove));
      QueryResponse oldTagQueryResponse = restApi.query(oldTagRequest);
         if(oldTagQueryResponse.getTotalResultCount() == 0){
         	System.out.println("Cannot find tag: " + tagToRemove);
             return;
         }
         JsonObject oldTagJsonObject = oldTagQueryResponse.getResults().get(0).getAsJsonObject();
       String oldTagRef = oldTagJsonObject.get("_ref").getAsString();
       System.out.println(oldTagRef);
      */
      QueryRequest newTagRequest = new QueryRequest("Tag");
      newTagRequest.setWorkspace(workspaceRef);
      newTagRequest.setQueryFilter(new QueryFilter("Name", "=", tagToAdd));
      QueryResponse newTagQueryResponse = restApi.query(newTagRequest);
      if (newTagQueryResponse.getTotalResultCount() == 0) {
        System.out.println("Cannot find tag: " + tagToAdd);
        return;
      }
      JsonObject newTagJsonObject = newTagQueryResponse.getResults().get(0).getAsJsonObject();
      String newTagRef = newTagJsonObject.get("_ref").getAsString();
      System.out.println(newTagRef);

      if (defectQueryResponse.getTotalResultCount() == 0) {
        System.out.println("Cannot find defects tagged : " + tagToRemove);
        return;
      } else {
        for (int i = 0; i < defectQueryResponse.getResults().size(); i++) {
          JsonObject defectJsonObject = defectQueryResponse.getResults().get(i).getAsJsonObject();
          String defectRef = defectJsonObject.get("_ref").getAsString();
          System.out.println(
              "Name: "
                  + defectJsonObject.get("Name")
                  + " FormattedID: "
                  + defectJsonObject.get("FormattedID"));
          int numberOfTags = defectJsonObject.getAsJsonObject("Tags").get("Count").getAsInt();
          QueryRequest tagCollectionRequest =
              new QueryRequest(defectJsonObject.getAsJsonObject("Tags"));
          tagCollectionRequest.setFetch(new Fetch("Name", "ObjectID"));
          JsonArray tags = restApi.query(tagCollectionRequest).getResults();
          for (int j = 0; j < numberOfTags; j++) {
            System.out.println("Tag Name: " + tags.get(j).getAsJsonObject().get("Name"));
          }
          tags.add(newTagJsonObject);
          JsonObject defectUpdate = new JsonObject();
          defectUpdate.add("Tags", tags);
          UpdateRequest updateDefectRequest = new UpdateRequest(defectRef, defectUpdate);
          UpdateResponse updateDefectResponse = restApi.update(updateDefectRequest);
          if (updateDefectResponse.wasSuccessful()) {
            System.out.println(
                "Successfully updated : "
                    + defectJsonObject.get("FormattedID")
                    + " Tags after update: ");
            QueryRequest tagCollectionRequest2 =
                new QueryRequest(defectJsonObject.getAsJsonObject("Tags"));
            tagCollectionRequest2.setFetch(new Fetch("Name", "ObjectID"));
            JsonArray tagsAfterUpdate = restApi.query(tagCollectionRequest2).getResults();
            int numberOfTagsAfterUpdate = restApi.query(tagCollectionRequest2).getResults().size();
            for (int j = 0; j < numberOfTagsAfterUpdate; j++) {
              System.out.println(
                  "Tag Name: " + tagsAfterUpdate.get(j).getAsJsonObject().get("Name"));
            }
          }
        }
      }

    } finally {
      restApi.close();
    }
  }
  private static void getRally(String oid) throws Exception {
    try {
      // start sub threads
      String host = "https://rally1.rallydev.com";
      String apiKey = "_56bw2obMSvaC3T6d4E0UTYdxFJqEpkNQoaFeesI7l94";
      String applicationName = "Nick multi thread example " + oid;
      RallyRestApi restApi = new RallyRestApi(new URI(host), apiKey);
      restApi.setApplicationName(applicationName);
      String workspaceRef = "/workspace/" + oid;
      QueryRequest releaseRequest = new QueryRequest("Release");
      releaseRequest.setFetch(
          new Fetch(
              "Name",
              "ObjectID",
              "ReleaseStartDate",
              "ReleaseDate",
              "Project",
              "RevisionHistory",
              "Revisions"));
      String date = getDate();
      releaseRequest.setQueryFilter(new QueryFilter("ReleaseDate", ">", date));
      releaseRequest.setWorkspace(workspaceRef);
      QueryResponse releaseQueryResponse = restApi.query(releaseRequest);
      int numberOfReleases = releaseQueryResponse.getTotalResultCount();
      System.out.println(
          "number of releases in workspace : "
              + oid
              + " with ReleaseDate > "
              + date
              + ":"
              + numberOfReleases);
      if (numberOfReleases > 0) {
        for (int i = 0; i < numberOfReleases; i++) {
          JsonObject releaseJsonObject = releaseQueryResponse.getResults().get(i).getAsJsonObject();
          System.out.println(
              releaseJsonObject.get("Name")
                  + " : "
                  + releaseJsonObject.get("ObjectID")
                  + " in project "
                  + releaseJsonObject.get("Project").getAsJsonObject().get("Name"));
          String rsd = releaseJsonObject.get("ReleaseStartDate").getAsString();
          String rd = releaseJsonObject.get("ReleaseDate").getAsString();

          JsonObject revisionHistory = releaseJsonObject.get("RevisionHistory").getAsJsonObject();
          QueryRequest revisionsRequest =
              new QueryRequest(revisionHistory.getAsJsonObject("Revisions"));
          revisionsRequest.setFetch(new Fetch("Description", "User", "UserName"));
          revisionsRequest.setQueryFilter(
              new QueryFilter("Description", "contains", "Unscheduled"));
          QueryResponse revisionsResponse = restApi.query(revisionsRequest);
          int numberOfRevisions = revisionsResponse.getTotalResultCount();
          if (numberOfRevisions > 0) {
            System.out.println(
                "number of revisions when work items were removed from release: "
                    + numberOfRevisions);
            for (int x = 0; x < numberOfRevisions; x++) {
              JsonObject revisionJsonObject =
                  revisionsResponse.getResults().get(x).getAsJsonObject();
              System.out.println(
                  revisionJsonObject.get("Description")
                      + "\n by:"
                      + revisionJsonObject.get("User").getAsJsonObject().get("UserName"));
            }
          } else {
            System.out.println("no work items were removed from release");
          }
        }
      }

    } finally {
      System.out.println(
          "done with thread " + oid + "\n--------------------------------------------------------");
    }
  }
  public static void main(String[] args)
      throws URISyntaxException, IOException, InterruptedException {

    // start main thread
    String host = "https://rally1.rallydev.com";
    String apiKey = "_abc123";
    String applicationName = "Nick multi thread example";
    RallyRestApi restApi = new RallyRestApi(new URI(host), apiKey);
    restApi.setApplicationName(applicationName);

    // get current user
    GetRequest getRequest = new GetRequest("/user");
    GetResponse getResponse = restApi.get(getRequest);
    JsonObject currentUser = getResponse.getObject();
    String currentUserRef = currentUser.get("_ref").getAsString();
    System.out.println("current user " + currentUserRef);

    // get workspaces where the current user has permission
    List<String> workspaces = new ArrayList<String>();
    QueryRequest workspacePermissionsRequest = new QueryRequest("WorkspacePermissions");
    workspacePermissionsRequest.setQueryFilter(new QueryFilter("User", "=", currentUserRef));
    workspacePermissionsRequest.setFetch(new Fetch("Workspace", "ObjectID"));

    QueryResponse workspacePermissionsResponse = restApi.query(workspacePermissionsRequest);
    int numberOfPermissoins = workspacePermissionsResponse.getTotalResultCount();
    System.out.println(numberOfPermissoins);
    if (numberOfPermissoins > 0) {
      for (int i = 0; i < numberOfPermissoins; i++) {
        JsonObject workspacePermissionObject =
            workspacePermissionsResponse.getResults().get(i).getAsJsonObject();
        String workspaceRef =
            workspacePermissionObject
                .get("Workspace")
                .getAsJsonObject()
                .get("ObjectID")
                .getAsString();
        workspaces.add(workspaceRef);
      }
    }
    System.out.println("workspaces " + workspaces);

    class MyRunnable implements Runnable {
      private String oid;

      public MyRunnable(String oid) {
        this.oid = oid;
      }

      public void run() {
        try {
          getRally(this.oid);
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    }
    Thread[] threads = new Thread[numberOfPermissoins];
    for (int i = 0; i < threads.length; i++) {
      threads[i] = new Thread(new MyRunnable(workspaces.get(i)));
      threads[i].start();
      threads[i].join();
    }
    if (restApi != null) {
      restApi.close();
    }
  }
  public static void main(String[] args) throws URISyntaxException, IOException {

    String host = "https://rally1.rallydev.com";
    String apiKey = "_abc123";
    String workspaceRef = "/workspace/12352608129";
    String applicationName = "Nick: updateMilestoneCollection";

    RallyRestApi restApi = new RallyRestApi(new URI(host), apiKey);
    restApi.setApplicationName(applicationName);

    try {
      String milestoneName = "Mid January";
      String storyId = "US30015";
      QueryRequest milestoneRequest = new QueryRequest("Milestone");
      milestoneRequest.setWorkspace(workspaceRef);
      milestoneRequest.setQueryFilter(new QueryFilter("Name", "=", milestoneName));
      QueryResponse milestoneQueryResponse = restApi.query(milestoneRequest);
      if (milestoneQueryResponse.getTotalResultCount() == 0) {
        System.out.println("Cannot find milestone: " + milestoneName);
        return;
      }
      JsonObject milestoneJsonObject = milestoneQueryResponse.getResults().get(0).getAsJsonObject();
      String milestoneRef = milestoneJsonObject.get("_ref").getAsString();
      System.out.println(milestoneRef);
      QueryRequest storyRequest = new QueryRequest("HierarchicalRequirement");
      storyRequest.setWorkspace(workspaceRef);
      storyRequest.setFetch(new Fetch("FormattedID", "Name", "Milestones"));
      storyRequest.setQueryFilter(new QueryFilter("FormattedID", "=", storyId));
      QueryResponse storyQueryResponse = restApi.query(storyRequest);
      ;

      if (storyQueryResponse.getTotalResultCount() == 0) {
        System.out.println("Cannot find story : " + storyId);
        return;
      }

      JsonObject storyJsonObject = storyQueryResponse.getResults().get(0).getAsJsonObject();
      String storyRef = storyJsonObject.get("_ref").getAsString();
      System.out.println(storyRef);
      int numberOfMilestones =
          storyJsonObject.getAsJsonObject("Milestones").get("Count").getAsInt();
      System.out.println(numberOfMilestones + " milestone(s) on " + storyId);
      QueryRequest milestoneCollectionRequest =
          new QueryRequest(storyJsonObject.getAsJsonObject("Milestones"));
      milestoneCollectionRequest.setFetch(new Fetch("Name"));
      JsonArray milestones = restApi.query(milestoneCollectionRequest).getResults();

      for (int j = 0; j < numberOfMilestones; j++) {
        System.out.println("Milestone Name: " + milestones.get(j).getAsJsonObject().get("Name"));
      }
      milestones.add(milestoneJsonObject);
      JsonObject storyUpdate = new JsonObject();
      storyUpdate.add("Milestones", milestones);
      UpdateRequest updateStoryRequest = new UpdateRequest(storyRef, storyUpdate);
      UpdateResponse updateStoryResponse = restApi.update(updateStoryRequest);
      if (updateStoryResponse.wasSuccessful()) {
        System.out.println("Successfully updated : " + storyId + " Milestones after update: ");
        QueryRequest milestoneCollectionRequest2 =
            new QueryRequest(storyJsonObject.getAsJsonObject("Milestones"));
        milestoneCollectionRequest2.setFetch(new Fetch("Name"));
        JsonArray milestonesAfterUpdate = restApi.query(milestoneCollectionRequest2).getResults();
        int numberOfMilestonesAfterUpdate =
            restApi.query(milestoneCollectionRequest2).getResults().size();
        for (int j = 0; j < numberOfMilestonesAfterUpdate; j++) {
          System.out.println(
              "Milestone Name: " + milestonesAfterUpdate.get(j).getAsJsonObject().get("Name"));
        }
      }
    } finally {
      restApi.close();
    }
  }