// Form validation
    @SuppressWarnings({"ThrowableResultOfMethodCallIgnored", "unused"})
    public FormValidation doTestConnection(
        @QueryParameter(CLIENT_ID) final String clientId,
        @QueryParameter(CLIENT_SECRET) final String clientSecret,
        @QueryParameter(BASE_URL) final String baseUrl) {
      if (clientId == null || clientId.isEmpty()) return FormValidation.error("API Key is empty!");
      if (clientSecret == null || clientSecret.isEmpty())
        return FormValidation.error("Secret Key is empty!");
      if (baseUrl == null || baseUrl.isEmpty())
        return FormValidation.error("Fortify on Demand URL is empty!");

      FodApi testApi = new FodApi(clientId, clientSecret, baseUrl);

      testApi.authenticate();
      String token = testApi.getToken();

      if (token == null) {
        return FormValidation.error("Unable to retrieve authentication token.");
      }

      return !token.isEmpty()
          ? FormValidation.ok("Successfully authenticated to Fortify on Demand.")
          : FormValidation.error(
              "Invalid connection information. Please check your credentials and try again.");
    }
 private void loadPluginOptions() {
   if (clientId != null && clientSecret != null && baseUrl != null) {
     api = new FodApi(clientId, clientSecret, baseUrl);
     api.authenticate();
     applications = api.getApplicationController().getApplications();
     releases = api.getReleaseController().getReleases(applications.get(0).getApplicationId());
     assessments =
         FilterNegativeEntitlements(
             api.getReleaseController().getAssessmentTypeIds(releases.get(0).getReleaseId()));
   }
 }
 @SuppressWarnings("unused")
 public ListBoxModel doFillReleaseIdItems(@QueryParameter(APPLICATION_ID) int applicationId) {
   ListBoxModel listBox = new ListBoxModel();
   api.authenticate();
   releases = api.getReleaseController().getReleases(applicationId);
   for (ReleaseDTO release : releases) {
     final String value = String.valueOf(release.getReleaseId());
     listBox.add(new ListBoxModel.Option(release.getReleaseName(), value, false));
   }
   return listBox;
 }
 @SuppressWarnings("unused")
 public ListBoxModel doFillAssessmentTypeIdItems(@QueryParameter(RELEASE_ID) int releaseId) {
   ListBoxModel listBox = new ListBoxModel();
   api.authenticate();
   assessments =
       FilterNegativeEntitlements(api.getReleaseController().getAssessmentTypeIds(releaseId));
   for (ReleaseAssessmentTypeDTO assessmentType : assessments) {
     final String value = String.valueOf(assessmentType.getAssessmentTypeId());
     String infoText;
     if (assessmentType.getFrequencyTypeId()
         == EntitlementFrequencyType.Subscription.getValue()) {
       infoText = "Subscription";
     } else {
       infoText =
           String.format("Single Scan: %s Unit(s) left", assessmentType.getUnitsAvailable());
     }
     final String name = String.format("%s (%s)", assessmentType.getName(), infoText);
     listBox.add(new ListBoxModel.Option(name, value, false));
   }
   return listBox;
 }
  // logic run during a build
  @Override
  public void perform(Run<?, ?> build, FilePath workspace, Launcher launcher, TaskListener listener)
      throws IOException {
    api.authenticate();

    final PrintStream logger = listener.getLogger();
    taskListener.set(listener);

    logger.println("Starting FoD Upload.");

    if (getAssessmentTypeId() == 0) {
      logger.println("Assessment Type is empty.");
      build.setResult(Result.FAILURE);
    }

    // zips the file in a temporary location
    File payload = CreateZipFile(workspace);
    if (payload.length() == 0) {
      logger.println("Source is empty for given Technology Stack and Language Level.");
      build.setResult(Result.FAILURE);
    }
    logger.println(jobModel.toString());

    jobModel.setUploadFile(payload);
    boolean success = api.getStaticScanController().startStaticScan(jobModel);
    boolean deleted = payload.delete();
    if (success && deleted) {
      logger.println("Scan Uploaded Successfully.");
      if (getDescriptor().getDoPollFortify() && jobModel.getPollingInterval() > 0) {
        PollStatus /*Amy*/ poller = new PollStatus(api, jobModel);
        success = poller.releaseStatus(getReleaseId());
      }
    }

    // Success could be true then set to false from polling.
    api.retireToken();
    build.setResult(success ? Result.SUCCESS : Result.UNSTABLE);
  }