예제 #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();
    }
  }
예제 #2
0
  public List<Violation> importViolations(Element violationsElement, List<Severity> severities)
      throws DatatypeConfigurationException {
    List<Violation> violations = new ArrayList<Violation>();
    for (Element violationElement : violationsElement.elements()) {
      Severity violationSeverity = null;

      final String severityId = violationElement.elementText("severityId");
      for (Severity severity : severities) {
        if (severityId.equals(severity.getId().toString())) {
          violationSeverity = severity;
          break;
        }
      }

      final int lineNumber = Integer.parseInt(violationElement.elementText("lineNumber"));
      final String ruleTypeKey = violationElement.elementText("ruletypeKey");
      final String violationTypeKey = violationElement.elementText("violationtypeKey");
      final String classPathFrom = violationElement.elementText("classPathFrom");
      final String classPathTo = violationElement.elementText("classPathTo");
      final LogicalModules logicalModules =
          getLogicalModules(violationElement.element("logicalModules"));
      final Message message = getMessage(violationElement.element("message"));
      final boolean isIndirect = Boolean.parseBoolean(violationElement.elementText("isIndirect"));

      final String stringCalendar = violationElement.elementText("occured");
      final Calendar occured = getCalendar(stringCalendar);

      Violation violation =
          new Violation()
              .setOccured(occured)
              .setLineNumber(lineNumber)
              .setSeverity(violationSeverity)
              .setRuletypeKey(ruleTypeKey)
              .setViolationTypeKey(violationTypeKey)
              .setClassPathFrom(classPathFrom)
              .setClassPathTo(classPathTo)
              .setInDirect(isIndirect)
              .setMessage(message)
              .setLogicalModules(logicalModules);

      violations.add(violation);
    }
    return violations;
  }