/**
   * Replace the existing property of a given type with a new property of a (possibly) different
   * type
   *
   * @param existingProperty the existing prop
   * @param newProperty the new prop that should replace the existing prop
   */
  private void replaceProperty(
      PropertyDefinition existingProperty, PropertyDefinition newProperty) {
    ConfigurationDefinition configDef = existingProperty.getConfigurationDefinition();

    // First take id from existing prop, and replace existing prop in the config def.
    newProperty.setId(existingProperty.getId());
    configDef.put(newProperty);

    entityManager.remove(existingProperty);
    entityManager.merge(configDef);
  }
  private ResourceType createResourceType() throws Exception {
    ResourceType resourceType =
        new ResourceType("RHQ Storage Node", "RHQStorage", ResourceCategory.SERVER, null);
    ConfigurationDefinition pluginConfigurationDefinition =
        new ConfigurationDefinition("config", null);
    pluginConfigurationDefinition.put(
        new PropertyDefinitionSimple("host", null, true, PropertySimpleType.STRING));
    resourceType.setPluginConfigurationDefinition(pluginConfigurationDefinition);
    getEntityManager().persist(resourceType);

    return resourceType;
  }
  static {
    DEFINITION.put(
        new PropertyDefinitionSimple("topLevelString", null, true, PropertySimpleType.STRING));
    DEFINITION.put(
        new PropertyDefinitionSimple("topLevelPassword", null, true, PropertySimpleType.PASSWORD));
    DEFINITION.put(
        new PropertyDefinitionList(
            "topLevelPasswordList",
            null,
            true,
            new PropertyDefinitionSimple("listPassword", null, true, PropertySimpleType.PASSWORD)));
    DEFINITION.put(
        new PropertyDefinitionList(
            "topLevelListOfMaps",
            null,
            true,
            new PropertyDefinitionMap(
                "mapWithPass",
                null,
                true,
                new PropertyDefinitionSimple("username", null, true, PropertySimpleType.STRING),
                new PropertyDefinitionSimple(
                    "password", null, true, PropertySimpleType.PASSWORD))));

    CONFIGURATION.put(new PropertySimple("topLevelString", "topLevelString"));
    CONFIGURATION.put(new PropertySimple("topLevelPassword", "topLevelPassword"));
    CONFIGURATION.put(
        new PropertyList(
            "topLevelPasswordList",
            new PropertySimple("listPassword", "0"),
            new PropertySimple("listPassword", "1")));
    CONFIGURATION.put(
        new PropertyList(
            "topLevelListOfMaps",
            new PropertyMap(
                "mapWithPass",
                new PropertySimple("username", "username"),
                new PropertySimple("password", "password"))));
  }
  public ConfigurationDefinitionUpdateReport updateConfigurationDefinition(
      ConfigurationDefinition newDefinition, ConfigurationDefinition existingDefinition) {

    ConfigurationDefinitionUpdateReport updateReport =
        new ConfigurationDefinitionUpdateReport(existingDefinition);

    /*
     * handle grouped and ungrouped properties separately. for ungrouped, we don't need to care about the group, but
     * for the grouped ones we need to start at group level and then look at the properties. This is done below.
     *
     * First look at the ungrouped ones.
     */

    List<PropertyDefinition> existingPropertyDefinitions =
        existingDefinition.getNonGroupedProperties();
    List<PropertyDefinition> newPropertyDefinitions = newDefinition.getNonGroupedProperties();
    if (existingPropertyDefinitions != null) {
      for (PropertyDefinition newProperty : newPropertyDefinitions) {
        PropertyDefinition existingProp = existingDefinition.get(newProperty.getName());
        if (existingProp != null) {
          log.debug("Updating nonGrouped property [" + existingProp + "]");

          updatePropertyDefinition(existingProp, newProperty);
          updateReport.addUpdatedPropertyDefinition(newProperty);
        } else {
          log.debug("Adding nonGrouped property [" + newProperty + "]");

          existingDefinition.put(newProperty);
          updateReport.addNewPropertyDefinition(newProperty);
        }
      }

      existingDefinition =
          removeNoLongerUsedProperties(
              newDefinition, existingDefinition, existingPropertyDefinitions);

    } else {
      // TODO what if existingDefinitions is null?
      // we probably don't run in here, as the initial persisting is done
      // somewhere else.
    }

    /*
     * Now update / delete contained groups We need to be careful here, as groups are present in PropertyDefinition
     * as "backlink" from PropertyDefinition to group
     */
    List<PropertyGroupDefinition> existingGroups = existingDefinition.getGroupDefinitions();
    List<PropertyGroupDefinition> newGroups = newDefinition.getGroupDefinitions();

    List<PropertyGroupDefinition> toPersist = missingInFirstList(existingGroups, newGroups);
    List<PropertyGroupDefinition> toDelete = missingInFirstList(newGroups, existingGroups);
    List<PropertyGroupDefinition> toUpdate = intersection(existingGroups, newGroups);

    // delete groups no longer present
    for (PropertyGroupDefinition group : toDelete) {
      List<PropertyDefinition> groupedDefinitions =
          existingDefinition.getPropertiesInGroup(group.getName());

      // first look for contained stuff
      for (PropertyDefinition def : groupedDefinitions) {
        log.debug("Removing property [" + def + "] from group [" + group + "]");

        existingPropertyDefinitions.remove(def);
        existingDefinition.getPropertyDefinitions().remove(def.getName());
        def.setPropertyGroupDefinition(null);
        entityManager.remove(def);
      }

      // then remove the definition itself
      log.debug("Removing group [" + group + "]");

      existingGroups.remove(group);
      entityManager.remove(group);
    }

    // update existing groups that stay
    for (PropertyGroupDefinition group : toUpdate) {
      String groupName = group.getName();

      List<PropertyDefinition> newGroupedDefinitions =
          newDefinition.getPropertiesInGroup(groupName);
      for (PropertyDefinition nDef : newGroupedDefinitions) {
        PropertyDefinition existingProperty =
            existingDefinition.getPropertyDefinitions().get(nDef.getName());
        if (existingProperty != null) {
          log.debug("Updating property [" + nDef + "] in group [" + group + "]");

          updatePropertyDefinition(existingProperty, nDef);
          updateReport.addUpdatedPropertyDefinition(nDef);

        } else {
          log.debug("Adding property [" + nDef + "] to group [" + group + "]");

          existingDefinition.put(nDef);
          updateReport.addNewPropertyDefinition(nDef);
        }
      }

      // delete outdated properties of this group
      existingDefinition =
          removeNoLongerUsedProperties(
              newDefinition,
              existingDefinition,
              existingDefinition.getPropertiesInGroup(groupName));
    }

    // persist new groups
    for (PropertyGroupDefinition group : toPersist) {

      // First persist a new group definition and then link the properties to it
      log.debug("Persisting new group [" + group + "]");

      entityManager.persist(group);
      existingGroups.add(group); // iterating over this does not update the underlying crap

      List<PropertyDefinition> defs = newDefinition.getPropertiesInGroup(group.getName());
      Map<String, PropertyDefinition> exPDefs = existingDefinition.getPropertyDefinitions();
      for (PropertyDefinition def : defs) {
        entityManager.persist(def);
        def.setPropertyGroupDefinition(group);
        def.setConfigurationDefinition(existingDefinition);

        if (!exPDefs.containsKey(def.getName())) {
          updateReport.addNewPropertyDefinition(def);
        }

        exPDefs.put(def.getName(), def);
      }
    }

    /*
     * Now work on the templates.
     */
    Map<String, ConfigurationTemplate> existingTemplates = existingDefinition.getTemplates();
    Map<String, ConfigurationTemplate> newTemplates = newDefinition.getTemplates();
    List<String> toRemove = new ArrayList<String>();
    List<String> templatesToUpdate = new ArrayList<String>();

    for (String name : existingTemplates.keySet()) {
      if (newTemplates.containsKey(name)) {
        templatesToUpdate.add(name);
      } else {
        toRemove.add(name);
      }
    }

    for (String name : toRemove) {
      log.debug("Removing template [" + name + "]");

      ConfigurationTemplate template = existingTemplates.remove(name);
      entityManager.remove(template);
    }

    for (String name : templatesToUpdate) {
      log.debug("Updating template [" + name + "]");

      updateTemplate(existingDefinition.getTemplate(name), newTemplates.get(name));
    }

    for (String name : newTemplates.keySet()) {
      // add completely new templates
      if (!existingTemplates.containsKey(name)) {
        log.debug("Adding template [" + name + "]");

        ConfigurationTemplate newTemplate = newTemplates.get(name);

        // we need to set a valid configurationDefinition, where we will live on.
        newTemplate.setConfigurationDefinition(existingDefinition);

        entityManager.persist(newTemplate);
        existingTemplates.put(name, newTemplate);
      }
    }

    return updateReport;
  }
  static {
    INSTANCE.setConfigurationFormat(ConfigurationFormat.STRUCTURED);
    INSTANCE.put(createName(INSTANCE, false));
    INSTANCE.put(createDescription(INSTANCE));
    INSTANCE.put(createEnabled(INSTANCE));
    INSTANCE.put(createDriftHandlingMode(INSTANCE));
    INSTANCE.put(createInterval(INSTANCE));
    INSTANCE.put(createBasedir(INSTANCE, false));
    INSTANCE.put(createIncludes(INSTANCE, false));
    INSTANCE.put(createExcludes(INSTANCE, false));
    INSTANCE.put(createPinned(INSTANCE, false));
    INSTANCE.put(createAttached(INSTANCE, false));

    INSTANCE_FOR_EXISTING_CONFIGS.setConfigurationFormat(ConfigurationFormat.STRUCTURED);
    INSTANCE_FOR_EXISTING_CONFIGS.put(createName(INSTANCE_FOR_EXISTING_CONFIGS, true));
    INSTANCE_FOR_EXISTING_CONFIGS.put(createDescription(INSTANCE_FOR_EXISTING_CONFIGS));
    INSTANCE_FOR_EXISTING_CONFIGS.put(createEnabled(INSTANCE_FOR_EXISTING_CONFIGS));
    INSTANCE_FOR_EXISTING_CONFIGS.put(createDriftHandlingMode(INSTANCE_FOR_EXISTING_CONFIGS));
    INSTANCE_FOR_EXISTING_CONFIGS.put(createInterval(INSTANCE_FOR_EXISTING_CONFIGS));
    INSTANCE_FOR_EXISTING_CONFIGS.put(createBasedir(INSTANCE_FOR_EXISTING_CONFIGS, true));
    INSTANCE_FOR_EXISTING_CONFIGS.put(createIncludes(INSTANCE_FOR_EXISTING_CONFIGS, true));
    INSTANCE_FOR_EXISTING_CONFIGS.put(createExcludes(INSTANCE_FOR_EXISTING_CONFIGS, true));
    INSTANCE_FOR_EXISTING_CONFIGS.put(createExcludes(INSTANCE_FOR_EXISTING_CONFIGS, true));
    INSTANCE_FOR_EXISTING_CONFIGS.put(createAttached(INSTANCE_FOR_EXISTING_CONFIGS, false));
    INSTANCE_FOR_EXISTING_CONFIGS.put(createPinned(INSTANCE_FOR_EXISTING_CONFIGS, false));

    NEW_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE.setConfigurationFormat(ConfigurationFormat.STRUCTURED);
    NEW_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE.put(
        createName(NEW_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE, false));
    NEW_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE.put(
        createDescription(NEW_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE));
    NEW_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE.put(
        createInterval(NEW_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE));
    NEW_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE.put(
        createEnabled(NEW_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE));
    NEW_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE.put(
        createDriftHandlingMode(NEW_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE));
    NEW_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE.put(
        createBasedir(NEW_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE, true));
    NEW_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE.put(
        createIncludes(NEW_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE, true));
    NEW_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE.put(
        createExcludes(NEW_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE, true));
    NEW_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE.put(
        createPinned(NEW_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE, true));
    NEW_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE.put(
        createAttached(NEW_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE, true));

    EXISTING_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE.setConfigurationFormat(
        ConfigurationFormat.STRUCTURED);
    EXISTING_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE.put(
        createName(EXISTING_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE, true));
    EXISTING_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE.put(
        createDescription(EXISTING_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE));
    EXISTING_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE.put(
        createInterval(EXISTING_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE));
    EXISTING_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE.put(
        createEnabled(EXISTING_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE));
    EXISTING_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE.put(
        createDriftHandlingMode(EXISTING_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE));
    EXISTING_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE.put(
        createBasedir(EXISTING_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE, true));
    EXISTING_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE.put(
        createIncludes(EXISTING_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE, true));
    EXISTING_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE.put(
        createExcludes(EXISTING_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE, true));
    EXISTING_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE.put(
        createPinned(EXISTING_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE, true));
    EXISTING_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE.put(
        createAttached(EXISTING_RESOURCE_INSTANCE_BY_PINNED_TEMPLATE, true));

    NEW_TEMPLATE_INSTANCE.setConfigurationFormat(ConfigurationFormat.STRUCTURED);
    NEW_TEMPLATE_INSTANCE.put(createName(NEW_TEMPLATE_INSTANCE, false));
    NEW_TEMPLATE_INSTANCE.put(createDescription(NEW_TEMPLATE_INSTANCE));
    NEW_TEMPLATE_INSTANCE.put(createInterval(NEW_TEMPLATE_INSTANCE));
    NEW_TEMPLATE_INSTANCE.put(createEnabled(NEW_TEMPLATE_INSTANCE));
    NEW_TEMPLATE_INSTANCE.put(createDriftHandlingMode(NEW_TEMPLATE_INSTANCE));
    NEW_TEMPLATE_INSTANCE.put(createBasedir(NEW_TEMPLATE_INSTANCE, false));
    NEW_TEMPLATE_INSTANCE.put(createIncludes(NEW_TEMPLATE_INSTANCE, false));
    NEW_TEMPLATE_INSTANCE.put(createExcludes(NEW_TEMPLATE_INSTANCE, false));

    EXISTING_TEMPLATE_INSTANCE.setConfigurationFormat(ConfigurationFormat.STRUCTURED);
    EXISTING_TEMPLATE_INSTANCE.put(createName(EXISTING_TEMPLATE_INSTANCE, true));
    EXISTING_TEMPLATE_INSTANCE.put(createDescription(EXISTING_TEMPLATE_INSTANCE));
    EXISTING_TEMPLATE_INSTANCE.put(createInterval(EXISTING_TEMPLATE_INSTANCE));
    EXISTING_TEMPLATE_INSTANCE.put(createEnabled(EXISTING_TEMPLATE_INSTANCE));
    EXISTING_TEMPLATE_INSTANCE.put(createDriftHandlingMode(EXISTING_TEMPLATE_INSTANCE));
    EXISTING_TEMPLATE_INSTANCE.put(createBasedir(EXISTING_TEMPLATE_INSTANCE, true));
    EXISTING_TEMPLATE_INSTANCE.put(createIncludes(EXISTING_TEMPLATE_INSTANCE, true));
    EXISTING_TEMPLATE_INSTANCE.put(createExcludes(EXISTING_TEMPLATE_INSTANCE, true));

    NEW_PINNED_TEMPLATE_INSTANCE.setConfigurationFormat(ConfigurationFormat.STRUCTURED);
    NEW_PINNED_TEMPLATE_INSTANCE.put(createName(NEW_PINNED_TEMPLATE_INSTANCE, false));
    NEW_PINNED_TEMPLATE_INSTANCE.put(createDescription(NEW_PINNED_TEMPLATE_INSTANCE));
    NEW_PINNED_TEMPLATE_INSTANCE.put(createInterval(NEW_PINNED_TEMPLATE_INSTANCE));
    NEW_PINNED_TEMPLATE_INSTANCE.put(createEnabled(NEW_PINNED_TEMPLATE_INSTANCE));
    NEW_PINNED_TEMPLATE_INSTANCE.put(createDriftHandlingMode(NEW_PINNED_TEMPLATE_INSTANCE));
    NEW_PINNED_TEMPLATE_INSTANCE.put(createBasedir(NEW_PINNED_TEMPLATE_INSTANCE, true));
    NEW_PINNED_TEMPLATE_INSTANCE.put(createIncludes(NEW_PINNED_TEMPLATE_INSTANCE, true));
    NEW_PINNED_TEMPLATE_INSTANCE.put(createExcludes(NEW_PINNED_TEMPLATE_INSTANCE, true));
  }
Beispiel #6
0
  /**
   * This returns the metadata describing the system settings.
   *
   * @param config the current configuration settings from the server. Some values will be converted
   *     to the types the definition will expect - for example, the JAAS setting will not be "LDAP"
   *     or "JDBC" as the server would know it, rather the value will be "true" or "false" (i.e. is
   *     ldap enabled or not?)
   * @param driftPlugins the set of drift server plugins that are currently deployed
   * @return system settings config def
   */
  private ConfigurationDefinition getSystemSettingsDefinition(
      Configuration config, Map<String, String> driftPlugins) {
    ConfigurationDefinition def =
        new ConfigurationDefinition("sysset", MSG.view_adminConfig_systemSettings());

    ///////////////////////////////////
    // General Configuration Properties

    PropertyGroupDefinition generalGroup = new PropertyGroupDefinition("general");
    generalGroup.setDisplayName(MSG.view_admin_systemSettings_group_general());
    generalGroup.setDefaultHidden(false);
    generalGroup.setOrder(0);

    PropertyDefinitionSimple baseUrl =
        new PropertyDefinitionSimple(
            Constant.BaseURL,
            MSG.view_admin_systemSettings_BaseURL_desc(),
            true,
            PropertySimpleType.STRING);
    baseUrl.setDisplayName(MSG.view_admin_systemSettings_BaseURL_name());
    baseUrl.setPropertyGroupDefinition(generalGroup);
    baseUrl.setDefaultValue("http://localhost:7080");
    def.put(baseUrl);

    PropertyDefinitionSimple agentMaxQuietTimeAllowed =
        new PropertyDefinitionSimple(
            Constant.AgentMaxQuietTimeAllowed,
            MSG.view_admin_systemSettings_AgentMaxQuietTimeAllowed_desc(),
            true,
            PropertySimpleType.INTEGER);
    agentMaxQuietTimeAllowed.setDisplayName(
        MSG.view_admin_systemSettings_AgentMaxQuietTimeAllowed_name());
    agentMaxQuietTimeAllowed.setPropertyGroupDefinition(generalGroup);
    agentMaxQuietTimeAllowed.addConstraints(
        new IntegerRangeConstraint(
            Long.valueOf(2),
            null)); // don't allow less than 2m since it will cause too many false backfills
    agentMaxQuietTimeAllowed.setDefaultValue("15");
    def.put(agentMaxQuietTimeAllowed);

    PropertyDefinitionSimple enableAgentAutoUpdate =
        new PropertyDefinitionSimple(
            Constant.EnableAgentAutoUpdate,
            MSG.view_admin_systemSettings_EnableAgentAutoUpdate_desc(),
            true,
            PropertySimpleType.BOOLEAN);
    enableAgentAutoUpdate.setDisplayName(
        MSG.view_admin_systemSettings_EnableAgentAutoUpdate_name());
    enableAgentAutoUpdate.setPropertyGroupDefinition(generalGroup);
    enableAgentAutoUpdate.setDefaultValue("true");
    def.put(enableAgentAutoUpdate);

    PropertyDefinitionSimple enableDebugMode =
        new PropertyDefinitionSimple(
            Constant.EnableDebugMode,
            MSG.view_admin_systemSettings_EnableDebugMode_desc(),
            true,
            PropertySimpleType.BOOLEAN);
    enableDebugMode.setDisplayName(MSG.view_admin_systemSettings_EnableDebugMode_name());
    enableDebugMode.setPropertyGroupDefinition(generalGroup);
    enableDebugMode.setDefaultValue("false");
    def.put(enableDebugMode);

    PropertyDefinitionSimple enableExperimentalFeatures =
        new PropertyDefinitionSimple(
            Constant.EnableExperimentalFeatures,
            MSG.view_admin_systemSettings_EnableExperimentalFeatures_desc(),
            true,
            PropertySimpleType.BOOLEAN);
    enableExperimentalFeatures.setDisplayName(
        MSG.view_admin_systemSettings_EnableExperimentalFeatures_name());
    enableExperimentalFeatures.setPropertyGroupDefinition(generalGroup);
    enableExperimentalFeatures.setDefaultValue("false");
    def.put(enableExperimentalFeatures);

    ////////////////////////////////////////
    // Data Manager Configuration Properties

    PropertyGroupDefinition dataManagerGroup = new PropertyGroupDefinition("datamanager");
    dataManagerGroup.setDisplayName(MSG.view_admin_systemSettings_group_dataMgr());
    dataManagerGroup.setDefaultHidden(false);
    dataManagerGroup.setOrder(1);

    PropertyDefinitionSimple dataMaintenance =
        new PropertyDefinitionSimple(
            Constant.DataMaintenance,
            MSG.view_admin_systemSettings_DataMaintenance_desc(),
            true,
            PropertySimpleType.INTEGER);
    dataMaintenance.setDisplayName(MSG.view_admin_systemSettings_DataMaintenance_name());
    dataMaintenance.setPropertyGroupDefinition(dataManagerGroup);
    dataMaintenance.addConstraints(new IntegerRangeConstraint(Long.valueOf(1), null));
    dataMaintenance.setDefaultValue("1");
    def.put(dataMaintenance);

    PropertyDefinitionSimple availabilityPurge =
        new PropertyDefinitionSimple(
            Constant.AvailabilityPurge,
            MSG.view_admin_systemSettings_AvailabilityPurge_desc(),
            true,
            PropertySimpleType.INTEGER);
    availabilityPurge.setDisplayName(MSG.view_admin_systemSettings_AvailabilityPurge_name());
    availabilityPurge.setPropertyGroupDefinition(dataManagerGroup);
    availabilityPurge.addConstraints(new IntegerRangeConstraint(Long.valueOf(1), null));
    availabilityPurge.setDefaultValue("365");
    def.put(availabilityPurge);

    PropertyDefinitionSimple alertPurge =
        new PropertyDefinitionSimple(
            Constant.AlertPurge,
            MSG.view_admin_systemSettings_AlertPurge_desc(),
            true,
            PropertySimpleType.INTEGER);
    alertPurge.setDisplayName(MSG.view_admin_systemSettings_AlertPurge_name());
    alertPurge.setPropertyGroupDefinition(dataManagerGroup);
    alertPurge.addConstraints(new IntegerRangeConstraint(Long.valueOf(1), null));
    alertPurge.setDefaultValue("31");
    def.put(alertPurge);

    PropertyDefinitionSimple traitPurge =
        new PropertyDefinitionSimple(
            Constant.TraitPurge,
            MSG.view_admin_systemSettings_TraitPurge_desc(),
            true,
            PropertySimpleType.INTEGER);
    traitPurge.setDisplayName(MSG.view_admin_systemSettings_TraitPurge_name());
    traitPurge.setPropertyGroupDefinition(dataManagerGroup);
    traitPurge.addConstraints(new IntegerRangeConstraint(Long.valueOf(1), null));
    traitPurge.setDefaultValue("365");
    def.put(traitPurge);

    PropertyDefinitionSimple rtDataPurge =
        new PropertyDefinitionSimple(
            Constant.RtDataPurge,
            MSG.view_admin_systemSettings_RtDataPurge_desc(),
            true,
            PropertySimpleType.INTEGER);
    rtDataPurge.setDisplayName(MSG.view_admin_systemSettings_RtDataPurge_name());
    rtDataPurge.setPropertyGroupDefinition(dataManagerGroup);
    rtDataPurge.addConstraints(new IntegerRangeConstraint(Long.valueOf(1), null));
    rtDataPurge.setDefaultValue("31");
    def.put(rtDataPurge);

    PropertyDefinitionSimple eventPurge =
        new PropertyDefinitionSimple(
            Constant.EventPurge,
            MSG.view_admin_systemSettings_EventPurge_desc(),
            true,
            PropertySimpleType.INTEGER);
    eventPurge.setDisplayName(MSG.view_admin_systemSettings_EventPurge_name());
    eventPurge.setPropertyGroupDefinition(dataManagerGroup);
    eventPurge.addConstraints(new IntegerRangeConstraint(Long.valueOf(1), null));
    eventPurge.setDefaultValue("14");
    def.put(eventPurge);

    PropertyDefinitionSimple driftFilePurge =
        new PropertyDefinitionSimple(
            Constant.DriftFilePurge,
            MSG.view_admin_systemSettings_DriftFilePurge_desc(),
            true,
            PropertySimpleType.INTEGER);
    driftFilePurge.setDisplayName(MSG.view_admin_systemSettings_DriftFilePurge_name());
    driftFilePurge.setPropertyGroupDefinition(dataManagerGroup);
    driftFilePurge.addConstraints(new IntegerRangeConstraint(Long.valueOf(1), null));
    driftFilePurge.setDefaultValue("31");
    def.put(driftFilePurge);

    PropertyDefinitionSimple dataReindex =
        new PropertyDefinitionSimple(
            Constant.DataReindex,
            MSG.view_admin_systemSettings_DataReindex_desc(),
            true,
            PropertySimpleType.BOOLEAN);
    dataReindex.setDisplayName(MSG.view_admin_systemSettings_DataReindex_name());
    dataReindex.setPropertyGroupDefinition(dataManagerGroup);
    dataReindex.setDefaultValue("true");
    def.put(dataReindex);

    //////////////////////////////////////////////
    // Automatic Baseline Configuration Properties

    PropertyGroupDefinition baselineGroup = new PropertyGroupDefinition("baseline");
    baselineGroup.setDisplayName(MSG.view_admin_systemSettings_group_baseline());
    baselineGroup.setDefaultHidden(false);
    baselineGroup.setOrder(2);

    PropertyDefinitionSimple baselineFrequency =
        new PropertyDefinitionSimple(
            Constant.BaselineFrequency,
            MSG.view_admin_systemSettings_BaselineFrequency_desc(),
            true,
            PropertySimpleType.INTEGER);
    baselineFrequency.setDisplayName(MSG.view_admin_systemSettings_BaselineFrequency_name());
    baselineFrequency.setPropertyGroupDefinition(baselineGroup);
    baselineFrequency.addConstraints(new IntegerRangeConstraint(Long.valueOf(0), null));
    baselineFrequency.setDefaultValue("3");
    def.put(baselineFrequency);

    PropertyDefinitionSimple baselineDataSet =
        new PropertyDefinitionSimple(
            Constant.BaselineDataSet,
            MSG.view_admin_systemSettings_BaselineDataSet_desc(),
            true,
            PropertySimpleType.INTEGER);
    baselineDataSet.setDisplayName(MSG.view_admin_systemSettings_BaselineDataSet_name());
    baselineDataSet.setPropertyGroupDefinition(baselineGroup);
    baselineDataSet.addConstraints(
        new IntegerRangeConstraint(
            Long.valueOf(1),
            Long.valueOf(14))); // can't do more than 14 days since our raw tables don't hold more
    baselineDataSet.setDefaultValue("7");
    def.put(baselineDataSet);

    ////////////////////////////////
    // LDAP Configuration Properties

    PropertyGroupDefinition ldapGroup = new PropertyGroupDefinition("ldap");
    ldapGroup.setDisplayName(MSG.view_admin_systemSettings_group_ldap());
    ldapGroup.setDefaultHidden(
        !Boolean.parseBoolean(
            config.getSimpleValue(Constant.JAASProvider, "false"))); // show if LDAP is in use
    ldapGroup.setOrder(3);

    PropertyDefinitionSimple jaasProvider =
        new PropertyDefinitionSimple(
            Constant.JAASProvider,
            MSG.view_admin_systemSettings_JAASProvider_desc(),
            true,
            PropertySimpleType.BOOLEAN);
    jaasProvider.setDisplayName(MSG.view_admin_systemSettings_JAASProvider_name());
    jaasProvider.setPropertyGroupDefinition(ldapGroup);
    jaasProvider.setDefaultValue("false");
    def.put(jaasProvider);

    PropertyDefinitionSimple ldapUrl =
        new PropertyDefinitionSimple(
            Constant.LDAPUrl,
            MSG.view_admin_systemSettings_LDAPUrl_desc(),
            true,
            PropertySimpleType.STRING);
    ldapUrl.setDisplayName(MSG.view_admin_systemSettings_LDAPUrl_name());
    ldapUrl.setPropertyGroupDefinition(ldapGroup);
    ldapUrl.setDefaultValue("ldap://localhost");
    def.put(ldapUrl);

    PropertyDefinitionSimple ldapProtocol =
        new PropertyDefinitionSimple(
            Constant.LDAPProtocol,
            MSG.view_admin_systemSettings_LDAPProtocol_desc(),
            true,
            PropertySimpleType.BOOLEAN);
    ldapProtocol.setDisplayName(MSG.view_admin_systemSettings_LDAPProtocol_name());
    ldapProtocol.setPropertyGroupDefinition(ldapGroup);
    ldapProtocol.setDefaultValue("false");
    def.put(ldapProtocol);

    PropertyDefinitionSimple ldapLoginProperty =
        new PropertyDefinitionSimple(
            Constant.LDAPLoginProperty,
            MSG.view_admin_systemSettings_LDAPLoginProperty_desc(),
            false,
            PropertySimpleType.STRING);
    ldapLoginProperty.setDisplayName(MSG.view_admin_systemSettings_LDAPLoginProperty_name());
    ldapLoginProperty.setPropertyGroupDefinition(ldapGroup);
    ldapLoginProperty.setDefaultValue("cn");
    def.put(ldapLoginProperty);

    PropertyDefinitionSimple ldapFilter =
        new PropertyDefinitionSimple(
            Constant.LDAPFilter,
            MSG.view_admin_systemSettings_LDAPFilter_desc(),
            false,
            PropertySimpleType.STRING);
    ldapFilter.setDisplayName(MSG.view_admin_systemSettings_LDAPFilter_name());
    ldapFilter.setPropertyGroupDefinition(ldapGroup);
    ldapFilter.setDefaultValue("");
    def.put(ldapFilter);

    PropertyDefinitionSimple ldapGroupFilter =
        new PropertyDefinitionSimple(
            Constant.LDAPGroupFilter,
            MSG.view_admin_systemSettings_LDAPGroupFilter_desc(),
            false,
            PropertySimpleType.STRING);
    ldapGroupFilter.setDisplayName(MSG.view_admin_systemSettings_LDAPGroupFilter_name());
    ldapGroupFilter.setPropertyGroupDefinition(ldapGroup);
    ldapGroupFilter.setDefaultValue("rhqadmin");
    def.put(ldapGroupFilter);

    PropertyDefinitionSimple ldapGroupMember =
        new PropertyDefinitionSimple(
            Constant.LDAPGroupMember,
            MSG.view_admin_systemSettings_LDAPGroupMember_desc(),
            false,
            PropertySimpleType.STRING);
    ldapGroupMember.setDisplayName(MSG.view_admin_systemSettings_LDAPGroupMember_name());
    ldapGroupMember.setPropertyGroupDefinition(ldapGroup);
    ldapGroupMember.setDefaultValue("");
    def.put(ldapGroupMember);

    PropertyDefinitionSimple ldapBaseDN =
        new PropertyDefinitionSimple(
            Constant.LDAPBaseDN,
            MSG.view_admin_systemSettings_LDAPBaseDN_desc(),
            false,
            PropertySimpleType.STRING);
    ldapBaseDN.setDisplayName(MSG.view_admin_systemSettings_LDAPBaseDN_name());
    ldapBaseDN.setPropertyGroupDefinition(ldapGroup);
    ldapBaseDN.setDefaultValue("o=RedHat,c=US");
    def.put(ldapBaseDN);

    PropertyDefinitionSimple ldapBindDN =
        new PropertyDefinitionSimple(
            Constant.LDAPBindDN,
            MSG.view_admin_systemSettings_LDAPBindDN_desc(),
            false,
            PropertySimpleType.STRING);
    ldapBindDN.setDisplayName(MSG.view_admin_systemSettings_LDAPBindDN_name());
    ldapBindDN.setPropertyGroupDefinition(ldapGroup);
    ldapBindDN.setDefaultValue("");
    def.put(ldapBindDN);

    PropertyDefinitionSimple ldapBindPW =
        new PropertyDefinitionSimple(
            Constant.LDAPBindPW,
            MSG.view_admin_systemSettings_LDAPBindPW_desc(),
            false,
            PropertySimpleType.PASSWORD);
    ldapBindPW.setDisplayName(MSG.view_admin_systemSettings_LDAPBindPW_name());
    ldapBindPW.setPropertyGroupDefinition(ldapGroup);
    ldapBindPW.setDefaultValue("");
    def.put(ldapBindPW);

    ///////////////////////////////////////////
    // Drift Server Configuration Properties //
    ///////////////////////////////////////////
    PropertyGroupDefinition driftGroup = new PropertyGroupDefinition("drift");
    driftGroup.setDisplayName(MSG.view_admin_systemSettings_group_drift());
    driftGroup.setOrder(4);
    driftGroup.setDefaultHidden(false);

    PropertyDefinitionSimple activeDriftServer =
        new PropertyDefinitionSimple(
            Constant.ACTIVE_DRIFT_PLUGIN,
            MSG.view_admin_systemSettings_ActiveDriftServerPlugin_desc(),
            true,
            PropertySimpleType.STRING);
    activeDriftServer.setDisplayName(MSG.view_admin_systemSettings_ActiveDriftServerPlugin_name());
    activeDriftServer.setPropertyGroupDefinition(driftGroup);

    List<PropertyDefinitionEnumeration> options = new ArrayList<PropertyDefinitionEnumeration>();
    for (Map.Entry<String, String> entry : driftPlugins.entrySet()) {
      options.add(new PropertyDefinitionEnumeration(entry.getValue(), entry.getKey()));
    }

    activeDriftServer.setEnumeratedValues(options, false);

    def.put(activeDriftServer);

    //
    // if the config is missing any properties for which we have defaults, set them to their
    // defaults
    //
    Map<String, PropertyDefinition> allDefinitions = def.getPropertyDefinitions();
    for (Map.Entry<String, PropertyDefinition> defEntry : allDefinitions.entrySet()) {
      String propertyName = defEntry.getKey();
      PropertyDefinition propertyDef = defEntry.getValue();
      if (config.get(propertyName) == null) {
        if (propertyDef instanceof PropertyDefinitionSimple
            && ((PropertyDefinitionSimple) propertyDef).getDefaultValue() != null) {
          config.put(
              new PropertySimple(
                  propertyName, ((PropertyDefinitionSimple) propertyDef).getDefaultValue()));
        }
      }
    }

    return def;
  }