Changeset 7297


Ignore:
Timestamp:
Feb 20, 2017, 3:11:16 PM (7 years ago)
Author:
Nicklas Nordborg
Message:

References #2056: Improve API for project-specific annotations

Added support in the SnapshotManager class to force loading default of project-specific annotation values ignoring the currently active project.

File:
1 edited

Legend:

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

    r7256 r7297  
    116116  {
    117117    this.snapshots = new HashMap<Integer, AnnotationSetSnapshot>();
     118  }
     119 
     120  private Integer projectId;
     121 
     122  /**
     123    When a project id is set, the snapshot manager will only
     124    search for project-specific annotations explicitely belonging
     125    to that project (or default values if projectId=0).
     126   
     127    Note that this parameter typically always need to be off (=null)
     128    when searching for annotations to an annotation type that
     129    doesn't have enabled project-specific annotations.
     130   
     131    @param projectId The project id or 0 to only search for default
     132      values or null to revert to the default behaviour
     133      (which load default values if a project-specific values
     134      doesn't exists)
     135    @since 3.11
     136  */
     137  public void setProjectId(Integer projectId)
     138  {
     139    this.projectId = projectId;
    118140  }
    119141 
     
    178200   
    179201    if (filter == null) filter = new StaticFilter<AnnotationSnapshot>(true);
    180     int activeProjectId = dc.getSessionControl().getActiveProjectId();
     202    int activeProjectId = projectId == null ?
     203      dc.getSessionControl().getActiveProjectId() : projectId;
    181204
    182205    // Needed for recursive searching of inherited annotations
     
    196219    for (AnnotationSnapshot shot : snapshot.getAnnotations())
    197220    {
     221      int shotProjectId = shot.getProjectId();
     222      // Ignore all annotations not belonging to the specified project
     223      if (projectId != null && shotProjectId != projectId) continue;
    198224      // Ignore project-specfic annotations not belonging to the current project
    199       int projectId = shot.getProjectId();
    200       if (projectId != 0 && projectId != activeProjectId) continue;
     225      if (shotProjectId != 0 && shotProjectId != activeProjectId) continue;
    201226     
    202227      // Ignore default annotations that already have a project-specific value
     
    214239          result.add(shot);
    215240          // This is a project-specific annotation overriding a default value
    216           if (projectId != 0) overridden.add(shot.getOverrideId());
     241          if (shotProjectId != 0) overridden.add(shot.getOverrideId());
    217242        }
    218243      }
     
    245270          {
    246271            result.add(shot);
    247             if (projectId != 0) overridden.add(shot.getOverrideId());
     272            if (shotProjectId != 0) overridden.add(shot.getOverrideId());
    248273          }
    249274        }
Note: See TracChangeset for help on using the changeset viewer.