/**
  * @param settingsProperty
  * @return <code>true</code> if the property should be hidden from the user
  */
 private boolean isHidden(SettingsProperty settingsProperty) {
   if (settingsProperty.getName().equals("Started")) {
     return true;
   } else if (settingsProperty.getName().equals("Mandatory")) {
     return true;
   } else if (settingsProperty.getName().equals("Database Version")) {
     return true;
   }
   return false;
 }
  public List<SettingsProperty> getSettings(String section) {
    List<SettingsProperty> settings = new ArrayList<SettingsProperty>();

    List<GlobalProperty> globalProperties = getService().getAllGlobalProperties();
    for (GlobalProperty globalProperty : globalProperties) {
      SettingsProperty property = new SettingsProperty(globalProperty);

      if (section.equals(property.getSection()) && !isHidden(property)) {
        settings.add(property);
      }
    }

    Collections.sort(settings);

    return settings;
  }
  @ModelAttribute(SECTIONS)
  public List<String> getSections() {
    SortedSet<String> sortedSections = new TreeSet<String>();
    List<GlobalProperty> globalProperties = getService().getAllGlobalProperties();
    for (GlobalProperty globalProperty : globalProperties) {
      SettingsProperty property = new SettingsProperty(globalProperty);
      if (!isHidden(property)) {
        sortedSections.add(property.getSection());
      }
    }

    List<String> sections = new ArrayList<String>();
    if (sortedSections.remove(SettingsProperty.GENERAL)) {
      sections.add(SettingsProperty.GENERAL);
    }
    sections.addAll(sortedSections);

    return sections;
  }
예제 #4
0
    private SettingsProperty(
        Object defaultValue,
        SettingsType type,
        SettingsSubType subType,
        SettingsProperty parent,
        SettingsPropertyType pType) {
      this.vclass = defaultValue.getClass();
      this.defaultValue = defaultValue;
      this.type = type;
      this.subType = subType;
      this.parent = parent;
      this.pType = pType;

      if (parent != null) {
        parent.setHasChild();
        if (!(parent.getDefaultValue() instanceof Boolean)) {
          throw new UnsupportedOperationException("Only boolean value can have a child");
        }
      }
    }
예제 #5
0
  public Class<?> getOptionClass(SettingsProperty property) {
    if (!(property.getDefaultValue() instanceof Class)) {
      return null;
    }

    try {
      return (Class<?>) Class.forName(get(property).replace("class ", ""));
    } catch (ClassNotFoundException ex) {
    }

    return null;
  }
  @RequestMapping(value = SETTINGS_PATH, method = RequestMethod.POST)
  public void updateSettings(
      @ModelAttribute(SETTINGS_FORM) SettingsForm settingsForm,
      Errors errors,
      HttpServletRequest request,
      HttpSession session) {

    List<GlobalProperty> toSave = new ArrayList<GlobalProperty>();
    try {
      for (int i = 0; i < settingsForm.getSettings().size(); ++i) {
        SettingsProperty property = settingsForm.getSettings().get(i);
        if (StringUtils.isNotEmpty(property.getGlobalProperty().getDatatypeClassname())) {
          // we need to handle the submitted value with the appropriate widget
          CustomDatatype dt = CustomDatatypeUtil.getDatatypeOrDefault(property.getGlobalProperty());
          CustomDatatypeHandler handler =
              CustomDatatypeUtil.getHandler(property.getGlobalProperty());
          if (handler != null) {
            try {
              Object value =
                  WebAttributeUtil.getValue(
                      request, dt, handler, "settings[" + i + "].globalProperty.propertyValue");
              property.getGlobalProperty().setValue(value);
            } catch (Exception ex) {
              String originalValue = request.getParameter("originalValue[" + i + "]");
              property.getGlobalProperty().setPropertyValue(originalValue);
              errors.rejectValue(
                  "settings[" + i + "].globalProperty.propertyValue", "general.invalid");
            }
          }
        }
        toSave.add(property.getGlobalProperty());
      }
    } catch (Exception e) {
      log.error("Error saving global property", e);
      errors.reject("GlobalProperty.not.saved");
      session.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, e.getMessage());
    }

    if (errors.hasErrors()) {
      session.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, "GlobalProperty.not.saved");

    } else {
      for (GlobalProperty gp : toSave) {
        getService().saveGlobalProperty(gp);
      }
      session.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "GlobalProperty.saved");

      // TODO: move this to a GlobalPropertyListener
      // refresh log level from global property(ies)
      OpenmrsUtil.applyLogLevels();

      OpenmrsUtil.setupLogAppenders();
    }
  }