private void validateActionAtEnd(Artifact actionArt) throws OseeCoreException {
    resultData.log("\nValidating End...");
    // Ensure event service is connected
    if (!OseeEventManager.isEventManagerConnected()) {
      resultData.logError("Remote Event Service is not connected");
      return;
    }
    resultData.log("Remote Event Service connected");

    // Validate values
    TeamWorkFlowArtifact teamArt = ActionManager.getFirstTeam(actionArt);
    testEquals(
        "Description",
        "description 4",
        teamArt.getSoleAttributeValue(AtsAttributeTypes.Description, null));
    testEquals("Change Type", ChangeType.Support, ChangeTypeUtil.getChangeType(teamArt));
    testEquals(
        "Priority", "3", teamArt.getSoleAttributeValue(AtsAttributeTypes.PriorityType, null));
    testEquals(
        "Validation Required",
        "false",
        String.valueOf(teamArt.getSoleAttributeValue(AtsAttributeTypes.ValidationRequired, null)));

    IAtsVersion verArt = AtsVersionService.get().getTargetedVersion(teamArt);
    String expectedTargetedVersion;
    if (verArt != null) {
      expectedTargetedVersion = verArt.toString();
    } else {
      expectedTargetedVersion = "not set";
    }
    testEquals("Targeted Version", expectedTargetedVersion, "2.5.7");
    testEquals("State", TeamState.Analyze.getName(), teamArt.getStateMgr().getCurrentStateName());
  }
  private void runDestinationTestEnd(String ttNum) throws OseeCoreException {
    String title = getName() + " - Destination Client Test - End";
    String actionTitle = "tt " + ttNum;
    resultData.log("Running " + title);

    Artifact actionArt =
        ArtifactQuery.getArtifactFromTypeAndName(
            AtsArtifactTypes.Action, actionTitle, AtsUtil.getAtsBranch());

    if (actionArt == null) {
      resultData.logError(String.format("Couldn't load Action named [%s]", actionTitle));
    } else {
      resultData.log("Loaded Action " + actionArt);
      AtsUtil.openATSAction(actionArt, AtsOpenOption.OpenOneOrPopupSelect);
    }
    validateActionAtEnd(actionArt);
    XResultDataUI.report(resultData, title);
  }
 private void testEquals(String name, Object expected, Object actual) {
   if (!expected.equals(actual)) {
     resultData.logError(
         String.format("Error: [%s] - expected [%s] actual[%s]", name, expected, actual));
   } else {
     resultData.log(
         String.format("Valid: [%s] - expected [%s] actual[%s]", name, expected, actual));
   }
 }
  private void validateActionAtStart(Artifact actionArt) throws OseeCoreException {
    resultData.log("\nValidating Start...");
    // Ensure event service is connected
    if (!OseeEventManager.isEventManagerConnected()) {
      resultData.logError("Remote Event Service is not connected");
      return;
    }
    resultData.log("Remote Event Service connected");

    // Validate values
    TeamWorkFlowArtifact teamArt = ActionManager.getFirstTeam(actionArt);
    testEquals(
        "Description",
        "description",
        teamArt.getSoleAttributeValue(AtsAttributeTypes.Description, null));
    testEquals("Change Type", ChangeType.Improvement, ChangeTypeUtil.getChangeType(teamArt));
    testEquals(
        "Priority", "1", teamArt.getSoleAttributeValue(AtsAttributeTypes.PriorityType, null));
  }
 public static IStatus runIt(
     IProgressMonitor monitor,
     String jobName,
     Collection<TeamWorkFlowArtifact> teamArts,
     IAttributeType attributeType) {
   XResultData rd = new XResultData();
   try {
     if (teamArts.isEmpty()) {
       throw new OseeStateException("No Actions/Workflows Specified");
     }
     retrieveData(monitor, teamArts, attributeType, rd);
     if (rd.toString().equals("")) {
       rd.log("No Problems Found");
     }
     final String html =
         XResultDataUI.getReport(rd, jobName)
             .getManipulatedHtml(Arrays.asList(Manipulations.NONE));
     final String title = jobName;
     Displays.pendInDisplayThread(
         new Runnable() {
           @Override
           public void run() {
             Result result = new HtmlExportTable(title, html, true, false).exportCsv();
             if (result.isFalse()) {
               AWorkbench.popup(result);
               return;
             }
             AWorkbench.popup(
                 title,
                 "Completed "
                     + title
                     + "\n\nFile saved to "
                     + System.getProperty("user.home")
                     + File.separator
                     + "table.csv");
           }
         });
     monitor.done();
     return Status.OK_STATUS;
   } catch (Exception ex) {
     OseeLog.log(Activator.class, Level.SEVERE, ex);
     return new Status(IStatus.ERROR, Activator.PLUGIN_ID, -1, "Failed", ex);
   }
 }
  /** used recursively when originally passed a directory, thus an array of files is accepted */
  private static void retrieveData(
      IProgressMonitor monitor,
      Collection<TeamWorkFlowArtifact> teamArts,
      IAttributeType attributeType,
      XResultData rd)
      throws OseeCoreException {
    monitor.subTask("Retrieving Actions");

    int x = 1;
    rd.addRaw(AHTML.beginMultiColumnTable(95));
    rd.addRaw(
        AHTML.addHeaderRowMultiColumnTable(
            new String[] {"HRID", "Bulld", "UI", attributeType.getName(), "RPCR", "Change"}));
    for (TeamWorkFlowArtifact teamArt : teamArts) {
      String rcprId = teamArt.getSoleAttributeValue(AtsAttributeTypes.LegacyPcrId, "");
      String result =
          String.format(
              "Processing %s/%s RPCR %s for \"%s\"",
              x, teamArts.size(), rcprId, teamArt.getTeamDefinition().getName());
      monitor.subTask(result);
      rd.log("\nRPCR " + rcprId);
      for (ICommitConfigArtifact commitConfigArt :
          AtsBranchManagerCore.getConfigArtifactsConfiguredToCommitTo(teamArt)) {
        processTeam(
            teamArt,
            BranchManager.getBranchByGuid(commitConfigArt.getBaslineBranchGuid()).getShortName(),
            attributeType,
            commitConfigArt,
            rd);
      }
      x++;

      //          System.err.println("Developmental purposes only, don't release with this");
      //          if (x >= 5)
      //          break;
    }
    rd.addRaw(AHTML.endMultiColumnTable());
  }
  private void runClientTest() throws OseeCoreException {
    String title = getName() + " - Destination Client Test";
    resultData.log("Running " + title);
    NewActionJob job = null;
    job =
        new NewActionJob(
            "tt",
            "description",
            ChangeType.Improvement,
            "1",
            null,
            false,
            getActionableItemsByToken(Arrays.asList(atsActionableItem)),
            null,
            null);
    job.setUser(true);
    job.setPriority(Job.LONG);
    job.schedule();
    try {
      job.join();
    } catch (InterruptedException ex) {
      OseeLog.log(Activator.class, Level.SEVERE, ex);
    }

    Artifact actionArt = job.getActionArt();
    resultData.log("Created Action " + actionArt);
    TeamWorkFlowArtifact teamArt = ActionManager.getFirstTeam(actionArt);

    // Make current user assignee for convenience to developer
    teamArt.getStateMgr().addAssignee(AtsClientService.get().getUserAdmin().getCurrentUser());
    teamArt.persist(getClass().getSimpleName());

    validateActionAtStart(actionArt);

    // Wait for destination client to start
    if (!MessageDialog.openConfirm(
        Displays.getActiveShell(),
        getName(),
        "Launch \"Destination Client - Start\" test, enter \""
            + actionArt.getName().replaceFirst("tt ", "")
            + "\" and press Ok")) {
      return;
    }

    int sleepTime = 250;
    makeChanges1(teamArt);
    sleep(sleepTime);
    makeChanges2(teamArt);
    sleep(sleepTime);
    makeChanges3(teamArt);
    sleep(sleepTime);
    makeChanges4(teamArt);
    sleep(sleepTime);
    makeChanges5(teamArt);
    sleep(sleepTime);
    makeChanges6(teamArt);
    sleep(sleepTime);
    makeChanges7(teamArt);
    sleep(sleepTime);

    validateActionAtEnd(actionArt);

    // Wait for destination client to end
    if (!MessageDialog.openConfirm(
        Displays.getActiveShell(),
        getName(),
        "Launch \"Destination Client - End\" test, enter \""
            + actionArt.getName().replaceFirst("tt ", "")
            + "\" and press Ok")) {
      return;
    }

    XResultDataUI.report(resultData, title);
  }