/** 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 static void processTeam(
     TeamWorkFlowArtifact teamArt,
     String buildId,
     IAttributeType attributeType,
     ICommitConfigArtifact commitConfigArt,
     XResultData rd)
     throws OseeCoreException {
   String rpcrNum = teamArt.getSoleAttributeValue(AtsAttributeTypes.LegacyPcrId, "");
   ChangeData changeData = AtsBranchManager.getChangeData(teamArt, commitConfigArt);
   for (Artifact modArt :
       changeData.getArtifacts(
           KindType.Artifact, ModificationType.NEW, ModificationType.MODIFIED)) {
     List<String> attrStrs = modArt.getAttributesToStringList(attributeType);
     if (attrStrs.isEmpty()) {
       attrStrs.add(EnumeratedAttribute.UNSPECIFIED_VALUE);
     }
     for (String attrStr : attrStrs) {
       rd.addRaw(
           AHTML.addRowMultiColumnTable(
               new String[] {
                 teamArt.getHumanReadableId(),
                 buildId,
                 modArt.getName(),
                 attrStr,
                 rpcrNum,
                 "Content"
               }));
     }
   }
   for (Artifact artChg : changeData.getArtifacts(KindType.Artifact, ModificationType.DELETED)) {
     List<String> attrStrs = artChg.getAttributesToStringList(attributeType);
     if (attrStrs.isEmpty()) {
       attrStrs.add(EnumeratedAttribute.UNSPECIFIED_VALUE);
     }
     for (String attrStr : attrStrs) {
       rd.addRaw(
           AHTML.addRowMultiColumnTable(
               new String[] {
                 teamArt.getHumanReadableId(),
                 buildId,
                 artChg.getName(),
                 attrStr,
                 rpcrNum,
                 "Deleted"
               }));
     }
   }
   for (Artifact artChg :
       changeData.getArtifacts(
           KindType.RelationOnly, ModificationType.NEW, ModificationType.MODIFIED)) {
     List<String> attrStrs = artChg.getAttributesToStringList(attributeType);
     if (attrStrs.isEmpty()) {
       attrStrs.add(EnumeratedAttribute.UNSPECIFIED_VALUE);
     }
     for (String attrStr : attrStrs) {
       rd.addRaw(
           AHTML.addRowMultiColumnTable(
               new String[] {
                 teamArt.getHumanReadableId(),
                 buildId,
                 artChg.getName(),
                 attrStr,
                 rpcrNum,
                 "Relation"
               }));
     }
   }
 }
Example #3
0
  public Result export(String speratorChar, String fileExtension) {
    if (!popupConfirm
        || popupConfirm
            && MessageDialog.openConfirm(
                Displays.getActiveShell(), "Export Table", "Export Table to CSV?")) {
      StringBuilder sb = new StringBuilder();
      sb.append(title + "\n");
      String htmlStr = AHTML.htmlToText(html);
      Matcher m =
          Pattern.compile(
                  "<table.*?</table>",
                  Pattern.CASE_INSENSITIVE | Pattern.DOTALL | Pattern.MULTILINE)
              .matcher(htmlStr);
      if (m.find()) {
        String csv = m.group();
        Matcher rowM =
            Pattern.compile(
                    "<tr.*?>(.*?)</tr>",
                    Pattern.CASE_INSENSITIVE | Pattern.DOTALL | Pattern.MULTILINE)
                .matcher(csv);
        while (rowM.find()) {
          String row = rowM.group(1);
          row = row.replaceAll("[\n\r]*", "");
          // Handle all the headers
          for (String tag : elementTags) {
            Matcher thM =
                Pattern.compile(
                        "<" + tag + ".*?>(.*?)</" + tag + ">",
                        Pattern.CASE_INSENSITIVE | Pattern.DOTALL | Pattern.MULTILINE)
                    .matcher(row);
            String csvRow = "";
            while (thM.find()) {
              String cellStr = removeLeadTrailSpaces(thM.group(1));
              String excelTextPrefix = (excelTextFields && !cellStr.contains(",")) ? "=" : "";
              csvRow += excelTextPrefix + "\"" + cellStr + "\"" + speratorChar;
            }
            if (!csvRow.equals("")) {
              csvRow = csvRow.replaceFirst(speratorChar + "$", "\n");
              sb.append(csvRow);
            }
          }
        }
        String path = "";
        if (popupConfirm) {
          FileDialog dialog = new FileDialog(Displays.getActiveShell(), SWT.SAVE | SWT.SINGLE);
          dialog.setFilterExtensions(new String[] {"*." + fileExtension});
          dialog.setFilterPath(System.getProperty("user.home"));
          dialog.setFileName("table.csv");
          path = dialog.open();
        } else {
          path = System.getProperty("user.home") + File.separator + "table." + fileExtension;
        }

        if (path != null) {
          try {
            File file = new File(path);
            Lib.writeStringToFile(sb.toString(), file);
            if (openInSystem) {
              Program.launch(file.getAbsolutePath());
            }
            return Result.TrueResult;
          } catch (IOException ex) {
            OseeLog.log(Activator.class, OseeLevel.SEVERE_POPUP, ex);
          }
        }
      } else {
        AWorkbench.popup("ERROR", "Can't find table in results.\n\nNothing to export");
      }
    }
    return Result.FalseResult;
  }
Example #4
0
  @Override
  public void run() {
    if (selectedCoverageEditorItem.getSelectedCoverageEditorItems().isEmpty()) {
      AWorkbench.popup("Select Coverage Item");
      return;
    }
    if (selectedCoverageEditorItem.getSelectedCoverageEditorItems().size() > 0) {
      ICoverage item =
          selectedCoverageEditorItem.getSelectedCoverageEditorItems().iterator().next();
      String highlightLine = null;

      try {
        if (item instanceof CoverageItem) {
          if (Strings.isValid(item.getName())) {
            highlightLine = item.getName();
          }
          item = item.getParent();
        }
        // If order number then parent has full file contents
        // attempt to find line in file that matches
        if (Strings.isValid(item.getOrderNumber())) {
          if (item.getParent() != null) {
            String itemLineText = item.getName();
            String parentFileContents = item.getParent().getFileContents();
            if (!Strings.isValid(parentFileContents)) {
              AWorkbench.popup("No File Contents Available");
              return;
            }
            String html = parentFileContents;
            // mark text for method
            if (Strings.isValid(itemLineText)) {
              html = html.replaceAll(itemLineText, "HEREBEGIN" + itemLineText + "HEREEND");
            }
            // mark text for executable line
            if (Strings.isValid(highlightLine)) {
              html = html.replaceAll(highlightLine, "HEREBEGIN" + highlightLine + "HEREEND");
            }
            html = AHTML.textToHtml(html);
            html = html.replaceAll(" ", "&nbsp;");
            html = html.replaceAll("HEREBEGIN", "<FONT style=\"BACKGROUND-COLOR: yellow\">");
            html = html.replaceAll("HEREEND", "</FONT>");
            ResultsEditor.open(
                "source",
                CoverageUtil.getFullPathWithName(item.getParent(), true)
                    + "["
                    + item.getName()
                    + "]",
                html);
          } else {
            AWorkbench.popup("No File Contents Available");
            return;
          }
        }
        // If no order number, just open full text
        else {
          String text = item.getFileContents();
          if (!Strings.isValid(text)) {
            AWorkbench.popup("No File Contents Available");
            return;
          }
          String html = AHTML.textToHtml(text);
          html = html.replaceAll(" ", "&nbsp;");
          ResultsEditor.open("source", CoverageUtil.getFullPathWithName(item, true), html);
        }

      } catch (OseeCoreException ex) {
        OseeLog.log(Activator.class, OseeLevel.SEVERE_POPUP, ex);
      }
    }
  }