コード例 #1
0
ファイル: RegisterRules.java プロジェクト: rbrindl/sonar
  private void disableDeprecatedUserRules(DatabaseSession session) {
    List<Integer> deprecatedUserRuleIds = Lists.newLinkedList();
    deprecatedUserRuleIds.addAll(
        session
            .createQuery(
                "SELECT r.id FROM "
                    + Rule.class.getSimpleName()
                    + " r WHERE r.parent IS NOT NULL AND NOT EXISTS(FROM "
                    + Rule.class.getSimpleName()
                    + " p WHERE r.parent=p)")
            .getResultList());

    deprecatedUserRuleIds.addAll(
        session
            .createQuery(
                "SELECT r.id FROM "
                    + Rule.class.getSimpleName()
                    + " r WHERE r.parent IS NOT NULL AND EXISTS(FROM "
                    + Rule.class.getSimpleName()
                    + " p WHERE r.parent=p and p.enabled=false)")
            .getResultList());

    for (Integer deprecatedUserRuleId : deprecatedUserRuleIds) {
      Rule rule = session.getSingleResult(Rule.class, "id", deprecatedUserRuleId);
      rule.setEnabled(false);
      session.saveWithoutFlush(rule);
    }
  }
コード例 #2
0
 private void importAlerts(RulesProfile profile) {
   if (profile.getAlerts() != null) {
     for (Iterator<Alert> ia = profile.getAlerts().iterator(); ia.hasNext(); ) {
       Alert alert = ia.next();
       Metric unMarshalledMetric = alert.getMetric();
       String validKey = unMarshalledMetric.getKey();
       Metric matchingMetricInDb = session.getSingleResult(Metric.class, "key", validKey);
       if (matchingMetricInDb == null) {
         LoggerFactory.getLogger(getClass()).error("Unable to find metric " + validKey);
         ia.remove();
         continue;
       }
       alert.setMetric(matchingMetricInDb);
       alert.setRulesProfile(profile);
     }
   }
 }
コード例 #3
0
ファイル: ProfilesConsole.java プロジェクト: ricesorry/sonar
 public ValidationMessages restoreProfile(String xmlBackup) {
   ValidationMessages messages = ValidationMessages.create();
   RulesProfile profile = xmlProfileParser.parse(new StringReader(xmlBackup), messages);
   if (profile != null) {
     DatabaseSession session = sessionFactory.getSession();
     RulesProfile existingProfile =
         session.getSingleResult(
             RulesProfile.class, "name", profile.getName(), "language", profile.getLanguage());
     if (existingProfile != null) {
       messages.addErrorText(
           "The profile " + profile + " already exists. Please delete it before restoring.");
     } else if (!messages.hasErrors()) {
       session.saveWithoutFlush(profile);
       session.commit();
     }
   }
   return messages;
 }
コード例 #4
0
  public Measure reloadMeasure(Measure measure) {
    if (measure.getId() != null
        && dataIdByMeasureId.containsKey(measure.getId())
        && !measure.hasData()) {
      Integer dataId = dataIdByMeasureId.get(measure.getId());
      MeasureData data = session.getSingleResult(MeasureData.class, "id", dataId);
      if (data == null) {
        LOG.error("The MEASURE_DATA row with id {} is lost", dataId);

      } else {
        if (LOG.isDebugEnabled()) {
          LOG.debug("Reload the data measure: {}, id={}", measure.getMetricKey(), measure.getId());
        }
        measure.setData(data.getText());
        loadedMeasures.add(measure);
      }
    }
    return measure;
  }
コード例 #5
0
ファイル: ProfilesConsole.java プロジェクト: ricesorry/sonar
 /** Important : the ruby controller has already create the profile */
 public ValidationMessages importProfile(
     String profileName, String language, String importerKey, String profileDefinition) {
   ValidationMessages messages = ValidationMessages.create();
   ProfileImporter importer = getProfileImporter(importerKey);
   RulesProfile profile = importer.importProfile(new StringReader(profileDefinition), messages);
   if (!messages.hasErrors()) {
     DatabaseSession session = sessionFactory.getSession();
     RulesProfile persistedProfile =
         session.getSingleResult(RulesProfile.class, "name", profileName, "language", language);
     for (ActiveRule activeRule : profile.getActiveRules()) {
       ActiveRule persistedActiveRule =
           persistedProfile.activateRule(activeRule.getRule(), activeRule.getSeverity());
       for (ActiveRuleParam activeRuleParam : activeRule.getActiveRuleParams()) {
         persistedActiveRule.setParameter(activeRuleParam.getKey(), activeRuleParam.getValue());
       }
     }
     session.saveWithoutFlush(persistedProfile);
     session.commit();
   }
   return messages;
 }
コード例 #6
0
ファイル: ProfilesConsole.java プロジェクト: ricesorry/sonar
 private RulesProfile loadProfile(DatabaseSession session, int profileId) {
   return session.getSingleResult(RulesProfile.class, "id", profileId);
 }