/**
   * Get the URL of the file to download. This has not been modified from the original version.
   *
   * <p>For more information, please see: <a href=
   * "https://collegereadiness.collegeboard.org/educators/higher-ed/reporting-portal-help#features">
   * https://collegereadiness.collegeboard.org/educators/higher-ed/reporting-
   * portal-help#features</a>
   *
   * <p>Original code can be accessed at: <a href=
   * "https://collegereadiness.collegeboard.org/zip/pascoredwnld-java-sample.zip">
   * https://collegereadiness.collegeboard.org/zip/pascoredwnld-java-sample.zip </a>
   *
   * @see #login(String, String)
   * @see org.collegeboard.scoredwnld.client.FileInfo
   * @author CollegeBoard
   * @param accessToken Access token obtained from {@link #login(String, String)}
   * @param filePath File to download
   * @return FileInfo descriptor of file to download
   */
  private FileInfo getFileUrlByToken(String accessToken, String filePath) {

    Client client = getClient();
    WebResource webResource =
        client.resource(
            scoredwnldUrlRoot + "/pascoredwnld/file?tok=" + accessToken + "&filename=" + filePath);
    ClientResponse response = webResource.accept("application/json").get(ClientResponse.class);
    if (response.getStatus() != 200) {
      throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
    }

    try {
      JSONObject json = new JSONObject(response.getEntity(String.class));
      FileInfo fileInfo = new FileInfo();
      fileInfo.setFileName(filePath);
      fileInfo.setFileUrl(String.valueOf(json.get("fileUrl")));
      return fileInfo;
    } catch (ClientHandlerException e) {
      log("Error: " + e.getMessage());
      e.printStackTrace();
    } catch (UniformInterfaceException e) {
      log("Error: " + e.getMessage());
      e.printStackTrace();
    } catch (JSONException e) {
      log("Error: " + e.getMessage());
      e.printStackTrace();
    }

    return null;
  }
Esempio n. 2
0
 // Code to add comments for Jira Issue
 public static void RestAddComment(String strComment, String strIssueID) {
   try {
     String auth = new String(Base64.encode("admin:admin"));
     String createCommentData = "{\"body\": \"" + strComment + "\"}\"";
     String comment =
         invokePostMethod(
             auth, BASE_URL + "/rest/api/2/issue/" + strIssueID + "/comment", createCommentData);
     System.out.println(comment);
     JSONObject issueObj = new JSONObject(comment);
     String newKey = issueObj.getString("id");
     System.out.println("id:" + newKey);
   } catch (AuthenticationException e) {
     System.out.println("Username or Password wrong!");
     e.printStackTrace();
   } catch (ClientHandlerException e) {
     System.out.println("Error invoking REST method");
     e.printStackTrace();
   } catch (JSONException e) {
     System.out.println("Invalid JSON output");
     e.printStackTrace();
   }
 }
Esempio n. 3
0
  /**
   * Run a CLI programmatically.
   *
   * <p>It does not exit the JVM.
   *
   * <p>A CLI instance can be used only once.
   *
   * @param args options and arguments for the Oozie CLI.
   * @return '0' (success), '-1' (failure).
   */
  public synchronized int run(final String[] args) {

    CLIParser parser = new CLIParser("falcon", FALCON_HELP);

    parser.addCommand(ADMIN_CMD, "", "admin operations", createAdminOptions(), true);
    parser.addCommand(HELP_CMD, "", "display usage", new Options(), false);
    parser.addCommand(VERSION_CMD, "", "show client version", new Options(), false);
    parser.addCommand(
        ENTITY_CMD,
        "",
        "Entity operations like submit, suspend, resume, delete, status, definition, submitAndSchedule",
        entityOptions(),
        false);
    parser.addCommand(
        INSTANCE_CMD,
        "",
        "Process instances operations like running, status, kill, suspend, resume, rerun, logs",
        instanceOptions(),
        false);
    parser.addCommand(GRAPH_CMD, "", "graph operations", createGraphOptions(), true);

    try {
      CLIParser.Command command = parser.parse(args);
      int exitValue = 0;
      if (command.getName().equals(HELP_CMD)) {
        parser.showHelp();
      } else {
        CommandLine commandLine = command.getCommandLine();
        String falconUrl = getFalconEndpoint(commandLine);
        FalconClient client = new FalconClient(falconUrl, clientProperties);

        if (command.getName().equals(ADMIN_CMD)) {
          exitValue = adminCommand(commandLine, client, falconUrl);
        } else if (command.getName().equals(ENTITY_CMD)) {
          entityCommand(commandLine, client);
        } else if (command.getName().equals(INSTANCE_CMD)) {
          instanceCommand(commandLine, client);
        } else if (command.getName().equals(GRAPH_CMD)) {
          graphCommand(commandLine, client);
        }
      }

      return exitValue;
    } catch (ParseException ex) {
      ERR.get().println("Invalid sub-command: " + ex.getMessage());
      ERR.get().println();
      ERR.get().println(parser.shortHelp());
      ERR.get().println("Stacktrace:");
      ex.printStackTrace();
      return -1;
    } catch (ClientHandlerException ex) {
      ERR.get()
          .print(
              "Unable to connect to Falcon server, "
                  + "please check if the URL is correct and Falcon server is up and running\n");
      ERR.get().println("Stacktrace:");
      ex.printStackTrace();
      return -1;
    } catch (Exception ex) {
      ERR.get().println("Stacktrace:");
      ex.printStackTrace();
      return -1;
    }
  }