Changeset 7496


Ignore:
Timestamp:
Jul 11, 2018, 2:42:30 PM (3 years ago)
Author:
Nicklas Nordborg
Message:

References #2125: Add support for hidden extended properties

It is now possible to set "hidden" attribute for an extended property. Hidden properties are usually not visible in the interface. They can still be modified via extensions or plug-ins.

Location:
trunk
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/net/sf/basedb/core/ClonableProperty.java

    r7052 r7496  
    250250    super(propertyName, title, description, column,
    251251      valueType, length, nullable, true, true,
    252       false, averageMethod, null);
     252      false, false, averageMethod, null);
    253253    this.isExtendedProperty = false;
    254254    this.isMandatory = isMandatory;
     
    263263    super(p.getName(), p.getTitle(), p.getDescription(), p.getColumn(),
    264264      p.getType(), p.getLength(), p.isNullable(), true, true,
    265       false, p.getAverageMethod(), null);
     265      false, false, p.getAverageMethod(), null);
    266266    this.isExtendedProperty = true;
    267267    this.isMandatory = false;
     
    278278    super(propertyName, d.getTitle(), d.getDescription(), d.getColumn(),
    279279      Type.fromValue(d.getValueType()), d.getLength(), d.isNullable(), true, true,
    280       false, AverageMethod.fromValue(d.getAverageMethod()), null);
     280      false, false, AverageMethod.fromValue(d.getAverageMethod()), null);
    281281    this.isExtendedProperty = d.isExtendedProperty();
    282282    this.isMandatory = d.isMandatory();
  • trunk/src/core/net/sf/basedb/core/ExtendedProperties.java

    r6881 r7496  
    3131import java.util.List;
    3232import java.util.ArrayList;
     33import java.util.Collections;
    3334import java.util.Map;
    3435import java.util.HashMap;
     
    7374
    7475  /**
     76    A map from class name --> a list of extended properties of for
     77    that class. The list holds {@link ExtendedProperty} objects that
     78    are not hidden.
     79    @since 3.13
     80  */
     81  private static Map<String, List<ExtendedProperty>> visibleProperties = null;
     82
     83 
     84  /**
    7585    The DTD which is used to validate the XML file.
    7686  */
     
    8999    classes = new ArrayList<String>();
    90100    allProperties = new HashMap<String, List<ExtendedProperty>>();
     101    visibleProperties = new HashMap<String, List<ExtendedProperty>>();
    91102    loadExtendedPropertiesFile();
    92103    isInitialised = true;
     
    102113    if (allProperties != null) allProperties.clear();
    103114    allProperties = null;
     115    if (visibleProperties != null) visibleProperties.clear();
     116    visibleProperties = null;
    104117    isInitialised = false;
    105118  }
     
    107120  /**
    108121    Load and parse the file with predefined queries.
    109     This method will populate the {@link #classes} and
    110     {@link #allProperties} variables.
     122    This method will populate the {@link #classes},
     123    {@link #allProperties} and {@link #visibleProperties} variables.
    111124  */
    112125  private static synchronized void loadExtendedPropertiesFile()
     
    159172
    160173  /**
    161     Get a list of extended properties for the specified class.
     174    Get a list of extended properties for the specified class. Hidden
     175    properties (introduced in BASE 3.13) are not included.
     176   
    162177    @param className The name of the class with or without
    163178      the package name
     
    168183  public static List<ExtendedProperty> getProperties(String className)
    169184  {
     185    return getProperties(className, false);
     186  }
     187
     188  /**
     189    Get a list of extended properties for the specified class.
     190   
     191    @param className The name of the class with or without
     192      the package name
     193    @param includeHidden A flag to indicate if hidden properties should be included or not
     194    @return A <code>List</code> object containing {@link ExtendedProperty}
     195      objects, or null if the specified class is not extendable or
     196      no extended properties has been defined
     197    @since 3.13
     198  */
     199  public static List<ExtendedProperty> getProperties(String className, boolean includeHidden)
     200  {
    170201    int index = className.lastIndexOf(".");
    171202    if (index >= 0)
     
    173204      className = className.substring(index+1);
    174205    }
    175     return allProperties.get(className);
     206    List<ExtendedProperty> properties = includeHidden ? allProperties.get(className) : visibleProperties.get(className);
     207    return properties == null ? null : Collections.unmodifiableList(properties);
    176208  }
    177209
     
    186218  public static ExtendedProperty getProperty(String className, String property)
    187219  {
    188     List<ExtendedProperty> l = getProperties(className);
     220    List<ExtendedProperty> l = getProperties(className, true);
    189221    if (l == null) return null;
    190222    for (ExtendedProperty e : l)
     
    209241        classes.add(className);
    210242        allProperties.put(className, new ArrayList<ExtendedProperty>());
     243        visibleProperties.put(className, new ArrayList<ExtendedProperty>());
    211244      }
    212245      loadProperties(usedNames, el, xmlFile);
     
    222255    String className = classElement.getAttributeValue("name");
    223256    List<ExtendedProperty> properties = allProperties.get(className);
     257    List<ExtendedProperty> visible = visibleProperties.get(className);
    224258    List<Element> children = classElement.getChildren("property");
    225259    DbEngine engine = HibernateUtil.getDbEngine();
     
    262296      boolean updateable = XmlUtil2.getBooleanAttribute(property, "update", true);
    263297      boolean restrictedEdit = XmlUtil2.getBooleanAttribute(property, "restricted-edit", false);
     298      boolean hidden = XmlUtil2.getBooleanAttribute(property, "hidden", false);
    264299      String avgMethod = property.getAttributeValue("averagemethod");
    265300      Formula.AverageMethod averageMethod = null;
     
    302337        }
    303338      }
    304       properties.add(new ExtendedProperty(name, title, description, column, type, length, nullable, insertable, updateable, restrictedEdit, averageMethod, epLinks));
     339      ExtendedProperty ep = new ExtendedProperty(name, title, description, column, type, length, nullable, insertable, updateable, restrictedEdit, hidden, averageMethod, epLinks);
     340      properties.add(ep);
     341      if (!hidden) visible.add(ep);
    305342    }
    306343  }
  • trunk/src/core/net/sf/basedb/core/ExtendedProperty.java

    r6898 r7496  
    6767  private final boolean updateable;
    6868  private final boolean restrictedEdit;
     69  private final boolean hidden;
    6970  private final Formula.AverageMethod averageMethod;
    7071  private final List<ExtendedPropertyLinker> linkers;
     
    7677  ExtendedProperty(String name, String title, String description, String column,
    7778    Type type, int length, boolean nullable, boolean insertable, boolean updateable,
    78     boolean restrictedEdit,
     79    boolean restrictedEdit, boolean hidden,
    7980    Formula.AverageMethod averageMethod, List<ExtendedPropertyLinker> linkers)
    8081  {
     
    8990    this.updateable = updateable;
    9091    this.restrictedEdit = restrictedEdit;
     92    this.hidden = hidden;
    9193    this.averageMethod = averageMethod;
    9294    this.linkers = linkers;
     
    191193  {
    192194    return restrictedEdit;
     195  }
     196 
     197  /**
     198    Check if the value of this property is hidden or not. Hidden properties should
     199    normally not show up in user interfaces that have not been specifically designed
     200    to work with the property.
     201    @since 3.13
     202  */
     203  public boolean isHidden()
     204  {
     205    return hidden;
    193206  }
    194207
  • trunk/src/core/net/sf/basedb/core/HibernateUtil.java

    r7469 r7496  
    448448  {
    449449    log.info("Adding extended properties to class: " + className);
    450     List<ExtendedProperty> properties = ExtendedProperties.getProperties(className);
     450    List<ExtendedProperty> properties = ExtendedProperties.getProperties(className, true);
    451451
    452452    for (ExtendedProperty property : properties)
  • trunk/src/core/net/sf/basedb/core/RawDataProperty.java

    r6428 r7496  
    4444    Type type, int length, boolean nullable, Formula.AverageMethod averageMethod, int channel)
    4545  {
    46     super(name, title, description, column, type, length, nullable, true, false, false, averageMethod, null);
     46    super(name, title, description, column, type, length, nullable, true, false, false, false, averageMethod, null);
    4747    this.channel = channel;
    4848  }
  • trunk/src/core/net/sf/basedb/core/ReporterBatcher.java

    r7381 r7496  
    9090    super(dc.getHibernateSession(), ReporterData.class, null);
    9191    entryDate = new Date();
    92     extendedProperties = ExtendedProperties.getProperties("ReporterData");
     92    extendedProperties = ExtendedProperties.getProperties("ReporterData", true);
    9393    batchedExternalIds = HibernateUtil.getDbEngine().caseInsensitiveComparison() ?
    9494      new TreeSet<String>(String.CASE_INSENSITIVE_ORDER) : new HashSet<String>();
  • trunk/src/core/net/sf/basedb/core/SessionControl.java

    r7494 r7496  
    779779      userData.setDescription(extraInfo.getDescription());
    780780     
    781       List<ExtendedProperty> properties = ExtendedProperties.getProperties("UserData");
     781      List<ExtendedProperty> properties = ExtendedProperties.getProperties("UserData", true);
    782782      if (properties != null)
    783783      {
  • trunk/src/core/net/sf/basedb/core/dtd/extended-properties.dtd

    r6428 r7496  
    4343  averagemethod (none|arithmetic_mean|geometric_mean|quadratic_mean|min|max) #IMPLIED
    4444  restricted-edit (true|false) "false"
     45  hidden (true|false) "false"
    4546>
    4647
  • trunk/www/admin/users/edit_user.jsp

    r7410 r7496  
    286286    <input type="hidden" name="cmd" value="UpdateItem">
    287287    <input type="hidden" name="item_id" value="<%=itemId%>">
    288 
     288   
    289289    <t:tabcontrol id="settings"
    290290      subclass="content dialogtabcontrol"
     
    557557        <table class="fullform input100">
    558558          <%
    559             for (ExtendedProperty ep : ExtendedProperties.getProperties("UserData"))
     559            for (ExtendedProperty ep : extendedProperties)
    560560            {
    561561              String name = ep.getName();
  • trunk/www/admin/users/index.jsp

    r7404 r7496  
    7272  import="java.util.ArrayList"
    7373  import="java.util.Collections"
     74  import="java.util.Map"
    7475%>
    7576<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
     
    258259     
    259260      // Extended properties
    260       List<ExtendedProperty> extendedProperties = ExtendedProperties.getProperties("UserData");
     261      List<ExtendedProperty> extendedProperties = ExtendedProperties.getProperties("UserData", true);
    261262      if (extendedProperties != null)
    262263      {
     264        Map<String, String[]> parameters = request.getParameterMap();
    263265        for (ExtendedProperty ep : extendedProperties)
    264266        {
    265267          String name = ep.getName();
    266           Formatter formatter = FormatterFactory.getExtendedPropertyFormatter(sc, ep);
    267           Object value = formatter.parseString(Values.getStringOrNull(request.getParameter("ep."+name)));
    268           user.setExtended(name, value);
     268          if (parameters.containsKey("ep."+name))
     269          {
     270            Formatter formatter = FormatterFactory.getExtendedPropertyFormatter(sc, ep);
     271            Object value = formatter.parseString(Values.getStringOrNull(request.getParameter("ep."+name)));
     272            user.setExtended(name, value);
     273          }
    269274        }
    270275      }
  • trunk/www/my_base/user/submit_user.jsp

    r7410 r7496  
    5050  import="java.util.Collections"
    5151  import="java.util.List"
     52  import="java.util.Map"
    5253%>
    5354<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
     
    103104
    104105    // Extended properties
    105     List<ExtendedProperty> extendedProperties = ExtendedProperties.getProperties("UserData");
     106    List<ExtendedProperty> extendedProperties = ExtendedProperties.getProperties("UserData", true);
    106107    if (extendedProperties != null)
    107108    {
     109      Map<String, String[]> parameters = request.getParameterMap();
    108110      for (ExtendedProperty ep : extendedProperties)
    109111      {
    110112        if (ep.isRestrictedEdit()) continue;
    111         String name = ep.getName();
    112         Formatter formatter = FormatterFactory.getExtendedPropertyFormatter(sc, ep);
    113         Object value = formatter.parseString(Values.getStringOrNull(request.getParameter("ep."+name)));
    114         user.setExtended(name, value);
     113        if (parameters.containsKey("ep."+name))
     114        {
     115          String name = ep.getName();
     116          Formatter formatter = FormatterFactory.getExtendedPropertyFormatter(sc, ep);
     117          Object value = formatter.parseString(Values.getStringOrNull(request.getParameter("ep."+name)));
     118          user.setExtended(name, value);
     119        }
    115120      }
    116121    }
  • trunk/www/views/reporters/edit_reporter.jsp

    r6387 r7496  
    236236        if (reporterProperties != null)
    237237        {
    238           for (ExtendedProperty ep : ExtendedProperties.getProperties("ReporterData"))
     238          for (ExtendedProperty ep : reporterProperties)
    239239          {
    240240            String name = ep.getName();
  • trunk/www/views/reporters/index.jsp

    r6315 r7496  
    5858  import="java.util.Enumeration"
    5959  import="java.util.List"
     60  import="java.util.Map"
    6061%>
    6162<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
     
    157158        if (rt != null) cc.setRecent(rt, maxRecent);
    158159      }
    159       List<ExtendedProperty> reporterProperties = ExtendedProperties.getProperties("ReporterData");
     160      List<ExtendedProperty> reporterProperties = ExtendedProperties.getProperties("ReporterData", true);
    160161      if (reporterProperties != null)
    161162      {
     163        Map<String, String[]> parameters = request.getParameterMap();
    162164        for (ExtendedProperty ep : reporterProperties)
    163165        {
    164166          String name = ep.getName();
    165           Formatter formatter = FormatterFactory.getExtendedPropertyFormatter(sc, ep);
    166           Object value = formatter.parseString(Values.getStringOrNull(request.getParameter("ep."+name)));
    167           reporter.setExtended(name, value);
     167          if (parameters.containsKey("ep."+name))
     168          {
     169            Formatter formatter = FormatterFactory.getExtendedPropertyFormatter(sc, ep);
     170            Object value = formatter.parseString(Values.getStringOrNull(request.getParameter("ep."+name)));
     171            reporter.setExtended(name, value);
     172          }
    168173        }
    169174      }
Note: See TracChangeset for help on using the changeset viewer.