Changeset 7024


Ignore:
Timestamp:
Nov 25, 2015, 8:34:50 AM (6 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #1972: Items not belonging to a project appear in the Project->Items list

This undo several changes made in [6934]. The generic filters are now defined the same way as before that change. Item-specific filters are defined only if there is an Item defined for the current class.

Location:
branches/3.6-stable/src/core/net/sf/basedb/core
Files:
1 edited
1 moved

Legend:

Unmodified
Added
Removed
  • branches/3.6-stable/src/core/net/sf/basedb/core/HibernateUtil.java

    r6966 r7024  
    432432    throws IOException
    433433  {
    434     Document filterDef = XmlUtil2.getValidatedXml(HibernateUtil.class.getResource("/net/sf/basedb/core/filter-def-template.xml"), dtdFile);
     434    Document filterDef = XmlUtil2.getValidatedXml(HibernateUtil.class.getResource("/net/sf/basedb/core/filter-def.hbm.xml"), dtdFile);
    435435    Map<String, Element> filters = new HashMap<String, Element>();
    436436    for (Element filter : filterDef.getRootElement().getChildren())
     
    453453      Class<?> c = Class.forName(className);
    454454      Item itemType = Item.fromClass(c);
     455
    455456      log.info("Adding 'denyAll' filter to "+c.getName());
    456       if (itemType == null) return;
    457      
    458457      defineFilter(classTag, itemType, "denyAll", "`id` != `id`", filterTemplate);
    459458      if (NewsData.class.isAssignableFrom(c))
     
    543542  private static void defineFilter(Element classTag, Item itemType, String name, String condition, Map<String, Element> filterTemplate)
    544543  {
    545     // Load the template
    546     Element filterSource = filterTemplate.get(name);
    547     if (filterSource == null) return;
    548 
    549     // Define the filter by cloning the template onto the root element
    550     classTag.getDocument().getRootElement().addContent(filterSource.clone());
    551     // We also need the same filter with name+itemtype so we have control
    552     // for each type of item
    553     Element filterDef = filterSource.clone();
    554     filterDef.setAttribute("name", name + itemType.name());
    555     classTag.getDocument().getRootElement().addContent(filterDef);
    556 
    557     // Second part of the filter definition goes inside the class tag
    558     Element filter = new Element("filter");
    559     filter.setAttribute("name", name);
    560     filter.setAttribute("condition", condition);
    561     classTag.addContent(filter);
    562    
    563     // And the name+itemtype variant
    564     filter = new Element("filter");
    565     filter.setAttribute("name", name + itemType.name());
    566     filter.setAttribute("condition", condition);
    567     classTag.addContent(filter);
     544    // Generic filter condition is only used for '<class>' elements (not '<subclass>')
     545    if (classTag.getName().equals("class"))
     546    {
     547      Element filter = new Element("filter");
     548      filter.setAttribute("name", name);
     549      filter.setAttribute("condition", condition);
     550      classTag.addContent(filter);
     551    }
     552   
     553    // Define item-specific filters with name+itemType so we have
     554    // control for each type of item
     555    if (itemType != null)
     556    {
     557      // Clone the definition from the template and change the name
     558      Element filterDef = filterTemplate.get(name).clone();
     559      filterDef.setAttribute("name", name + itemType.name());
     560      classTag.getDocument().getRootElement().addContent(filterDef);
     561     
     562      // Enable the filter for the current '<class>' or '<subclass>'
     563      Element filter = new Element("filter");
     564      filter.setAttribute("name", name + itemType.name());
     565      filter.setAttribute("condition", condition);
     566      classTag.addContent(filter);
     567    }
    568568  }
    569569 
Note: See TracChangeset for help on using the changeset viewer.