Changeset 6728


Ignore:
Timestamp:
Feb 13, 2015, 9:00:01 AM (7 years ago)
Author:
Nicklas Nordborg
Message:

References #1910: Disable annotation inheritance for annotation types

Added AnnotationType.getDisableInheritance() which is a flag that if set will disable the inheritance. Schema version is updated and all existing annotation types are set to FALSE.

A permission check when calling AnnotationSet.inheritAnnotation has been implemented and setting the flag with AnnotationType.setDisableInheritance() will trigger a removal of existing inherited annotations.

This should complete the core part of the functionality but we also need some supporting functionality (mainly in the gui).

Location:
trunk
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/common-queries.xml

    r6631 r6728  
    19491949  </query>
    19501950 
     1951  <query id="LOAD_ANNOTATIONSET_INHERITING_ANNOTATIONTYPE" type="SQL">
     1952    <sql>
     1953      SELECT [ia].[annotationset_id] FROM [InheritedAnnotations] [ia]
     1954      INNER JOIN [Annotations] [a] ON [a].[id] = [ia].[annotation_id]
     1955      WHERE [a].[annotationtype_id] = :annotationType
     1956    </sql>
     1957    <description>
     1958      An SQL query that load the ID of all annotation sets that
     1959      are inheriting a given annotation type.
     1960    </description>
     1961  </query>
     1962 
     1963  <query id="DELETE_INHERITED_ANNOTATIONS" type="SQL">
     1964    <sql>
     1965      DELETE FROM [InheritedAnnotations]
     1966      WHERE [annotation_id] IN (
     1967        SELECT [id] FROM [Annotations] WHERE [annotationtype_id] = :annotationType
     1968      )
     1969    </sql>
     1970    <description>
     1971      An SQL query that delete all directly inherited annotations of the specified
     1972      annotation type.
     1973    </description>
     1974  </query>
     1975 
    19511976  <query id="UPDATE_BYTES_FOR_EXPERIMENT" type="HQL">
    19521977    <sql>
  • trunk/src/core/net/sf/basedb/core/AnnotationSet.java

    r6721 r6728  
    755755    @throws PermissionDeniedException If the logged in user
    756756      doesn't have write permission for this annotation set or
    757       use permission for the annotation
     757      use permission for the annotation or if the annotation type is not
     758      enabled for inheritance
    758759    @throws InvalidDataException If the annotation is null
    759760  */
     
    764765    if (annotation == null) throw new InvalidUseOfNullException("annotation");
    765766    annotation.checkPermission(Permission.USE);
     767    if (annotation.getAnnotationType().getDisableInheritance())
     768    {
     769      throw new PermissionDeniedException("Inheritance has been disabled on " + annotation.getAnnotationType());
     770    }
    766771    if (getData().getInherited().add(annotation.getData()))
    767772    {
  • trunk/src/core/net/sf/basedb/core/AnnotationType.java

    r6465 r6728  
    913913  }
    914914
    915  
     915  /**
     916    If this flag is set, annotations of this type can't be inherited
     917    to child items. Use this to prevent sensitive data from being used
     918    in other contexts.
     919    @since 3.5
     920  */
     921  public boolean getDisableInheritance()
     922  {
     923    return getData().getDisableInheritance();
     924  }
     925 
     926  /**
     927    If this flag is set, annotations of this type can't be inherited
     928    to child items. Use this to prevent sensitive data from being used
     929    in other contexts. Changing this from FALSE to TRUE will automatically
     930    trigger a database action that remove all existing inherited annotations
     931    of this type.
     932    @throws PermissionDeniedException If the logged in user doesn't
     933      have write permission
     934    @since 3.5
     935  */
     936  public void setDisableInheritance(boolean disableInheritance)
     937    throws PermissionDeniedException
     938  {
     939    checkPermission(Permission.WRITE);
     940    if (disableInheritance && !getData().getDisableInheritance() && isInDatabase())
     941    {
     942      getDbControl().addTransactionalAction(new RemoveInheritedAnnotationsAction(this));
     943    }
     944    getData().setDisableInheritance(disableInheritance);
     945  }
     946
    916947  /**
    917948    Get the minumum allowed value for an {@link Type#INT} or {@link Type#LONG}
     
    14081439  }
    14091440 
     1441  static class RemoveInheritedAnnotationsAction
     1442    implements TransactionalAction
     1443  {
     1444    private final AnnotationType at;
     1445   
     1446    public RemoveInheritedAnnotationsAction(AnnotationType at)
     1447    {
     1448      this.at = at;
     1449    }
     1450
     1451    @Override
     1452    public void onBeforeCommit()
     1453    {
     1454      // Verify that the disable flag is still set
     1455      if (at.getDisableInheritance())
     1456      {
     1457        DbControl dc = at.getDbControl();
     1458        org.hibernate.Session session = dc.getHibernateSession();
     1459       
     1460        org.hibernate.Query query = HibernateUtil.getPredefinedSQLQuery(session, "LOAD_ANNOTATIONSET_INHERITING_ANNOTATIONTYPE");
     1461        query.setInteger("annotationType", at.getId());
     1462        List<Integer> ids = HibernateUtil.loadList(Integer.class, query, dc.getSessionControl());
     1463        SnapshotManager.removeSnapshots(ids);
     1464       
     1465        query = HibernateUtil.getPredefinedSQLQuery(session, "DELETE_INHERITED_ANNOTATIONS");
     1466        query.setInteger("annotationType", at.getId());
     1467        query.executeUpdate();
     1468      }
     1469    }
     1470
     1471    // Nothing to do
     1472    @Override
     1473    public void onAfterCommit()
     1474    {}
     1475
     1476    // Nothing to do
     1477    @Override
     1478    public void onRollback()
     1479    {}
     1480   
     1481  }
    14101482}
  • trunk/src/core/net/sf/basedb/core/Install.java

    r6631 r6728  
    118118    method.
    119119  */
    120   public static final int NEW_SCHEMA_VERSION = Integer.valueOf(118).intValue();
     120  public static final int NEW_SCHEMA_VERSION = Integer.valueOf(119).intValue();
    121121 
    122122  public static synchronized int createTables(SchemaGenerator.Mode mode, ProgressReporter progress,
  • trunk/src/core/net/sf/basedb/core/Update.java

    r6631 r6728  
    210210    </td>
    211211  </tr>
     212  <tr>
     213    <td>119</td>
     214    <td>
     215      Added {@link AnnotationTypeData#getDisableInheritance()}.
     216      The update will set the value to FALSE for all existing annotation types.
     217    </td>
     218  </tr>
    212219  </table>
    213220
     
    331338      }
    332339     
    333       if (schemaVersion < 118)
    334       {
    335         if (progress != null) progress.display((int)(progress_current), "--Updating schema version: " + schemaVersion + " -> 118...");
    336         // Schemaversion 118 only updates the version number
    337         schemaVersion = setSchemaVersionInTransaction(session, 118);
     340      if (schemaVersion < 119)
     341      {
     342        if (progress != null) progress.display((int)(progress_current), "--Updating schema version: " + schemaVersion + " -> 119...");
     343        // Schemaversion 118-119 only updates the version number
     344        schemaVersion = setSchemaVersionInTransaction(session, 119);
    338345        progress_current += progress_step;
    339346      }
     
    568575          "SET sv.appId = :appId WHERE sv.appId IS NULL");
    569576        query.setString("appId", SchemaVersionData.BASE_APP_ID);
     577        query.executeUpdate();
     578      }
     579     
     580      if (schemaVersion < 119)
     581      {
     582        // Set disableInheritance=false on all annotation types
     583        org.hibernate.Query query = HibernateUtil.createQuery(session,
     584          "UPDATE AnnotationTypeData at " +
     585          "SET at.disableInheritance = false " +
     586          "WHERE at.disableInheritance IS NULL");
    570587        query.executeUpdate();
    571588      }
  • trunk/src/core/net/sf/basedb/core/data/AnnotationTypeData.java

    r6358 r6728  
    264264  }
    265265
     266  private boolean disableInheritance;
     267  /**
     268    If this flag is set, annotation of this type can't be inherited.
     269    @since 3.5
     270    @hibernate.property column="`disable_inherit`" type="boolean" not-null="true"
     271  */
     272  public boolean getDisableInheritance()
     273  {
     274    return disableInheritance;
     275  }
     276  public void setDisableInheritance(boolean disableInheritance)
     277  {
     278    this.disableInheritance = disableInheritance;
     279  }
     280 
    266281  private Set<Integer> itemTypes;
    267282  /**
  • trunk/src/core/net/sf/basedb/core/snapshot/SnapshotManager.java

    r6721 r6728  
    7676    String cacheKey = getCacheKey(annotationSetId);
    7777    return cache.delete(cacheKey, 1000);
     78  }
     79 
     80  /**
     81    Removes a list of snapshots from the static cache.
     82    @param annotationSetIds A list with IDs of annotation set  s
     83    @return The number of successfully removed snapshots
     84    @since 3.5
     85  */
     86  public static int removeSnapshots(List<Integer> annotationSetIds)
     87  {
     88    StaticCache cache = Application.getStaticCache();
     89    int removed = 0;
     90    for (Integer i : annotationSetIds)
     91    {
     92      String cacheKey = getCacheKey(i);
     93      if (cache.delete(cacheKey, 1000)) removed++;
     94    }
     95    return removed;
    7896  }
    7997 
  • trunk/www/admin/annotationtypes/edit_annotationtype.jsp

    r6684 r6728  
    398398        <td></td>
    399399      </tr>
     400      <tr>
     401        <th><label for="disable_inheritance">Disable inheritance</label></th>
     402        <td><input type="checkbox" name="disable_inheritance" id="disable_inheritance" value="1"
     403          <%=(annotationType != null && annotationType.getDisableInheritance()) ||
     404            (annotationType == null && Values.getBoolean(cc.getPropertyValue("disableInheritance"))) ? "checked" : ""%>
     405          >
     406        </td>
     407        <td></td>
     408      </tr>
    400409      <tr class="dynamic">
    401410        <th>Description</th>
  • trunk/www/admin/annotationtypes/index.jsp

    r6358 r6728  
    191191      annotationType.setProtocolParameter(Values.getBoolean(request.getParameter("is_protocol_parameter")));
    192192      annotationType.setDisableLogOfValues(Values.getBoolean(request.getParameter("disable_log")));
     193      annotationType.setDisableInheritance(Values.getBoolean(request.getParameter("disable_inheritance")));
    193194      if (annotationType.getValueType().canEnumerate())
    194195      {
  • trunk/www/admin/annotationtypes/list_annotationtypes.jsp

    r6706 r6728  
    281281      />
    282282      <tbl:columndef
     283        id="disableInheritance"
     284        property="disableInheritance"
     285        datatype="boolean"
     286        title="Disable inheritance"
     287        sortable="true"
     288        filterable="true"
     289        exportable="true"
     290      />
     291      <tbl:columndef
    283292        id="isEnumeration"
    284293        property="enumeration"
     
    603612                <tbl:cell column="isProtocolParameter"><%=item.isProtocolParameter() ? "yes" : "no"%></tbl:cell>
    604613                <tbl:cell column="disableLogOfValues"><%=item.getDisableLogOfValues() ? "yes" : "no"%></tbl:cell>
     614                <tbl:cell column="disableInheritance"><%=item.getDisableInheritance() ? "yes" : "no"%></tbl:cell>
    605615                <tbl:cell column="multiplicity"><%=item.getMultiplicity() == 0 ? "<i>- unlimited -</i>" : item.getMultiplicity()%></tbl:cell>
    606616                <tbl:cell column="defaultValue"><%=HTML.encodeTags(item.getDefaultValue())%></tbl:cell>
  • trunk/www/admin/annotationtypes/view_annotationtype.jsp

    r6605 r6728  
    278278        <th>Disable change log</th>
    279279        <td><%=annotationType.getDisableLogOfValues() ? "yes" : "no"%></td>
     280      </tr>
     281      <tr>
     282        <th>Disable inheritance</th>
     283        <td><%=annotationType.getDisableInheritance() ? "yes" : "no"%></td>
    280284      </tr>
    281285      <tr>
Note: See TracChangeset for help on using the changeset viewer.