Exemplo n.º 1
0
  private ViolationDTO createViolationDTO(Violation violation)
      throws RuleInstantionException, LanguageNotFoundException, RuleTypeNotFoundException {
    try {
      RuleTypeDTO rule = createRuleTypeDTO(violation);
      ViolationTypeDTO violationtype = rule.getViolationTypes()[0];

      final String classPathFrom = violation.getClassPathFrom();
      final String classPathTo = violation.getClassPathTo();
      final String logicalModuleFromPath =
          violation.getLogicalModules().getLogicalModuleFrom().getLogicalModulePath();
      final String logicalModuleToPath =
          violation.getLogicalModules().getLogicalModuleTo().getLogicalModulePath();
      final String message = messagebuilder.createMessage(violation.getMessage());
      final int linenumber = violation.getLinenumber();

      if (violation.getSeverity() != null) {
        final Severity severity = violation.getSeverity();
        final Color color = severity.getColor();
        final String userDefinedName = severity.getUserName();
        final String systemDefinedName = severity.getDefaultName();
        final int severityValue = configuration.getSeverityValue(violation.getSeverity());

        return new ViolationDTO(
            classPathFrom,
            classPathTo,
            logicalModuleFromPath,
            logicalModuleToPath,
            violationtype,
            rule,
            message,
            linenumber,
            color,
            userDefinedName,
            systemDefinedName,
            severityValue);
      } else {
        return new ViolationDTO(
            classPathFrom,
            classPathTo,
            logicalModuleFromPath,
            logicalModuleToPath,
            violationtype,
            rule,
            message,
            linenumber,
            Color.BLACK,
            "",
            "",
            0);
      }
    } catch (ViolationTypeNotFoundException e) {
      throw new ViolationTypeNotFoundException();
    }
  }
Exemplo n.º 2
0
  private void createTable() throws DocumentException {
    Phrase title = new Phrase();
    title.setFont(new Font(FontFamily.HELVETICA, 13F, Font.BOLD, BaseColor.BLUE));
    title.add("Violations");
    document.add(new Paragraph(title));
    document.add(new Paragraph(" "));

    PdfPTable pdfTable = new PdfPTable(report.getLocaleColumnHeaders().length);
    pdfTable.setWidths(new int[] {3, 4, 1, 2, 2, 1});
    pdfTable.setWidthPercentage(100);

    for (String columnHeader : report.getLocaleColumnHeaders()) {
      addCellToTable(pdfTable, columnHeader, BaseColor.GRAY, true);
    }

    for (Violation violation : report.getViolations().getValue()) {
      // Source
      if (violation.getClassPathFrom() != null && !violation.getClassPathFrom().trim().equals("")) {
        addCellToTable(pdfTable, violation.getClassPathFrom(), BaseColor.WHITE, false);
      } else {
        addCellToTable(pdfTable, "", BaseColor.WHITE, false);
      }

      // Rule
      if (violation.getMessage() != null) {
        String message = new Messagebuilder().createMessage(violation.getMessage(), violation);
        addCellToTable(pdfTable, message, BaseColor.WHITE, false);
      } else {
        addCellToTable(pdfTable, "", BaseColor.WHITE, false);
      }

      // LineNumber
      if (!(violation.getLinenumber() == 0)) {
        addCellToTable(pdfTable, "" + violation.getLinenumber(), BaseColor.WHITE, false);
      } else {
        addCellToTable(pdfTable, "", BaseColor.WHITE, false);
      }

      // DependencyKind
      if (violation.getViolationTypeKey() != null) {
        addCellToTable(
            pdfTable,
            getDependencyKindValue(violation.getViolationTypeKey(), violation.isIndirect()),
            BaseColor.WHITE,
            false);
      } else {
        addCellToTable(pdfTable, "", BaseColor.WHITE, false);
      }
      // Target
      if (violation.getClassPathFrom() != null && !violation.getClassPathFrom().trim().equals("")) {
        addCellToTable(pdfTable, violation.getClassPathTo(), BaseColor.WHITE, false);
      } else {
        addCellToTable(pdfTable, "", BaseColor.WHITE, false);
      }

      // Severity
      if (violation.getSeverity() != null) {
        addCellToTable(
            pdfTable, "" + violation.getSeverity().getSeverityName(), BaseColor.WHITE, false);
      } else {
        addCellToTable(pdfTable, "", BaseColor.WHITE, false);
      }
    }

    document.add(pdfTable);
  }