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; }
private ActiveRuleType containsRuleType( List<ActiveRuleType> activeRuleTypes, String ruleTypeKey) { for (ActiveRuleType activeRuleType : activeRuleTypes) { if (activeRuleType.getRuleType().equals(ruleTypeKey)) { return activeRuleType; } } throw new RuntimeException(); }
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); }
private ActiveRuleType initializeActiveViolationTypes(RuleType ruleType) { final String ruleTypeKey = ruleType.getKey(); List<ActiveViolationType> initialActiveViolationTypes = new ArrayList<ActiveViolationType>(); for (ViolationType violationType : ruleType.getViolationTypes()) { final String violationTypeKey = violationType.getViolationtypeKey(); boolean enabled = violationType.isActive(); ActiveViolationType activeViolationType = new ActiveViolationType(violationTypeKey, enabled); initialActiveViolationTypes.add(activeViolationType); } ActiveRuleType activeRuleType = new ActiveRuleType(ruleTypeKey); activeRuleType.setViolationTypes(initialActiveViolationTypes); return activeRuleType; }
private boolean violationTypeKeyExists( String programmingLanguage, String ruleTypeKey, String violationTypeKey) { if (programmingLanguageExists(programmingLanguage) && ruleTypeKeyExists(programmingLanguage, ruleTypeKey)) { for (ActiveRuleType activeRuleType : startupViolationTypes.get(programmingLanguage)) { for (ActiveViolationType activeViolationType : activeRuleType.getViolationTypes()) { if (activeViolationType.getType().toLowerCase().equals(violationTypeKey.toLowerCase())) { return true; } } } } throw new ViolationTypeNotFoundException(violationTypeKey); }
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; }
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); }