コード例 #1
0
  boolean isEnabled(String programmingLanguage, String ruleTypeKey, String violationTypeKey) {
    List<ActiveRuleType> activeRuleTypes =
        this.currentActiveViolationTypes.get(programmingLanguage);
    if (activeRuleTypes != null) {
      for (ActiveRuleType activeRuleType : activeRuleTypes) {
        if (activeRuleType.getRuleType().toLowerCase().equals(ruleTypeKey.toLowerCase())) {

          if (activeRuleType.getViolationTypes().isEmpty()) {
            return false;
          }

          for (ActiveViolationType activeViolationType : activeRuleType.getViolationTypes()) {
            if (activeViolationType
                .getType()
                .toLowerCase()
                .equals(violationTypeKey.toLowerCase())) {
              return activeViolationType.isEnabled();
            }
          }
        }
      }
    } else {
      throw new ProgrammingLanguageNotFoundException();
    }
    return false;
  }
コード例 #2
0
  private List<ActiveRuleType> mergeNewViolationTypes(
      String programmingLanguage, List<ActiveRuleType> newActiveViolationTypes) {
    List<ActiveRuleType> activeViolationTypesForLanguage = new ArrayList<ActiveRuleType>();

    for (ActiveRuleType currentActiveRuleType : startupViolationTypes.get(programmingLanguage)) {
      try {
        ActiveRuleType existingActiveRuleType =
            containsRuleType(newActiveViolationTypes, currentActiveRuleType.getRuleType());
        List<ActiveViolationType> activeViolationTypes = new ArrayList<ActiveViolationType>();

        for (ActiveViolationType currentActiveViolationType :
            containsRuleType(
                    startupViolationTypes.get(programmingLanguage),
                    existingActiveRuleType.getRuleType())
                .getViolationTypes()) {
          boolean found = false;
          for (ActiveViolationType newViolationType : existingActiveRuleType.getViolationTypes()) {
            if (newViolationType.getType().equals(currentActiveViolationType.getType())) {
              activeViolationTypes.add(newViolationType);
              found = true;
            }
          }
          if (!found) {
            activeViolationTypes.add(
                new ActiveViolationType(
                    currentActiveViolationType.getType(), currentActiveViolationType.isEnabled()));
          }
        }
        activeViolationTypesForLanguage.add(
            new ActiveRuleType(existingActiveRuleType.getRuleType(), activeViolationTypes));

      } catch (RuntimeException e) {
        List<ActiveViolationType> activeViolationTypes = new ArrayList<ActiveViolationType>();
        for (ActiveViolationType activeViolationType : currentActiveRuleType.getViolationTypes()) {
          activeViolationTypes.add(
              new ActiveViolationType(
                  activeViolationType.getType(), activeViolationType.isEnabled()));
        }
        ActiveRuleType activeRuleType =
            new ActiveRuleType(currentActiveRuleType.getRuleType(), activeViolationTypes);
        activeViolationTypesForLanguage.add(activeRuleType);
      }
    }
    return activeViolationTypesForLanguage;
  }
コード例 #3
0
 private ActiveRuleType containsRuleType(
     List<ActiveRuleType> activeRuleTypes, String ruleTypeKey) {
   for (ActiveRuleType activeRuleType : activeRuleTypes) {
     if (activeRuleType.getRuleType().equals(ruleTypeKey)) {
       return activeRuleType;
     }
   }
   throw new RuntimeException();
 }
コード例 #4
0
  private boolean ruleTypeKeyExists(String programmingLanguage, String ruleTypeKey) {
    if (programmingLanguageExists(programmingLanguage)) {

      for (ActiveRuleType activeRuleType : startupViolationTypes.get(programmingLanguage)) {
        if (activeRuleType.getRuleType().toLowerCase().equals(ruleTypeKey.toLowerCase())) {
          return true;
        }
      }
    } else {
      throw new ProgrammingLanguageNotFoundException(programmingLanguage);
    }
    throw new RuleTypeNotFoundException(ruleTypeKey);
  }
コード例 #5
0
  private List<ActiveRuleType> checkNewActiveViolationTypes(
      String programmingLanguage, List<ActiveRuleType> newActiveViolationTypes) {
    List<ActiveRuleType> activeViolationTypesForLanguage = new ArrayList<ActiveRuleType>();

    for (ActiveRuleType newActiveRuleType : newActiveViolationTypes) {
      if (ruleTypeKeyExists(programmingLanguage, newActiveRuleType.getRuleType())) {

        List<ActiveViolationType> activeViolationTypes = new ArrayList<ActiveViolationType>();
        ActiveRuleType activeRuleType = new ActiveRuleType(newActiveRuleType.getRuleType());
        activeRuleType.setViolationTypes(activeViolationTypes);
        boolean foundViolationTypeKey = false;

        for (ActiveViolationType newActiveViolationType : newActiveRuleType.getViolationTypes()) {
          if (violationTypeKeyExists(
              programmingLanguage,
              newActiveRuleType.getRuleType(),
              newActiveViolationType.getType())) {
            foundViolationTypeKey = true;
            activeViolationTypes.add(
                new ActiveViolationType(
                    newActiveViolationType.getType(), newActiveViolationType.isEnabled()));
          } else {
            logger.debug(
                String.format("violationTypeKey %s not exists", newActiveViolationType.getType()));
          }
        }
        if (foundViolationTypeKey) {
          activeViolationTypesForLanguage.add(activeRuleType);
        }
      } else {
        logger.debug(
            String.format(
                "ruleTypeKey %s not exists in programminglanguage %s",
                newActiveRuleType.getRuleType(), programmingLanguage));
      }
    }
    return mergeNewViolationTypes(programmingLanguage, activeViolationTypesForLanguage);
  }