@Override
  public String execute() throws Exception {
    selectedAttributes = attributeService.getTrackedEntityAttributesDisplayInList();

    Collections.sort(
        selectedAttributes, new TrackedEntityAttributeSortOrderInListNoProgramComparator());

    return SUCCESS;
  }
  @Override
  public String execute() throws Exception {
    OptionSet optionSet = optionService.getOptionSet(optionSetId);

    valueType =
        optionSet != null && optionSet.getValueType() != null
            ? optionSet.getValueType()
            : valueType;

    TrackedEntityAttribute trackedEntityAttribute =
        trackedEntityAttributeService.getTrackedEntityAttribute(id);

    trackedEntityAttribute.setName(StringUtils.trimToNull(name));
    trackedEntityAttribute.setShortName(StringUtils.trimToNull(shortName));
    trackedEntityAttribute.setCode(StringUtils.trimToNull(code));
    trackedEntityAttribute.setDescription(StringUtils.trimToNull(description));
    trackedEntityAttribute.setValueType(valueType);
    trackedEntityAttribute.setAggregationType(AggregationType.fromValue(aggregationType));
    trackedEntityAttribute.setExpression(expression);
    trackedEntityAttribute.setDisplayOnVisitSchedule(false);
    trackedEntityAttribute.setOptionSet(optionSet);

    unique = unique != null;
    trackedEntityAttribute.setUnique(unique);

    inherit = inherit != null;
    trackedEntityAttribute.setInherit(inherit);

    confidential = confidential != null;
    trackedEntityAttribute.setConfidential(confidential);

    if (unique) {
      boolean orgunitScope = false;
      boolean programScope = false;

      if (Objects.equals(scope, SCOPE_ORGUNIT) || Objects.equals(scope, SCOPE_PROGRAM_IN_ORGUNIT)) {
        orgunitScope = true;
      }

      if (Objects.equals(scope, SCOPE_PROGRAM) || Objects.equals(scope, SCOPE_PROGRAM_IN_ORGUNIT)) {
        programScope = true;
      }

      trackedEntityAttribute.setOrgunitScope(orgunitScope);
      trackedEntityAttribute.setProgramScope(programScope);
    } else if (ValueType.TRACKER_ASSOCIATE == valueType) {
      trackedEntityAttribute.setTrackedEntity(
          trackedEntityService.getTrackedEntity(trackedEntityId));
    }

    if (legendSetId != null) {
      trackedEntityAttribute.setLegendSet(legendService.getLegendSet(legendSetId));
    }

    if (jsonAttributeValues != null) {
      AttributeUtils.updateAttributeValuesFromJson(
          trackedEntityAttribute.getAttributeValues(), jsonAttributeValues, attributeService);
    }

    trackedEntityAttributeService.updateTrackedEntityAttribute(trackedEntityAttribute);

    return SUCCESS;
  }