Changeset 6937


Ignore:
Timestamp:
Aug 7, 2015, 8:34:06 AM (6 years ago)
Author:
Nicklas Nordborg
Message:

References #1941: Store experimental factor values as part experiments

Removing the annotation on a parent item will nullify the link from cloned annotations instead of removing the clones.

Other changes are related to fixing various NullPointerExceptions and other problems resulting from having "inherited" annotations without a parent item.

But more work is needed on this since the cloned annotations now end up in a state that is almost impossible to manage via the gui. The "batch inherit annotations" can be used to remove or update cloned annotation.

Location:
trunk
Files:
8 edited

Legend:

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

    r6920 r6937  
    19581958  </query>
    19591959 
     1960  <query id="NULLIFY_LINK_FROM_CLONES" type="HQL">
     1961    <sql>
     1962      UPDATE AnnotationData ad
     1963      SET ad.inheritedFrom = null
     1964      WHERE ad.inheritedFrom = :targetId
     1965      AND ad.source = 2
     1966    </sql>
     1967    <description>
     1968      A HQL query that nullify the link from all cloned annotations
     1969      to a specified target annotation.
     1970    </description>
     1971  </query>
     1972 
    19601973  <query id="UPDATE_BYTES_FOR_EXPERIMENT" type="HQL">
    19611974    <sql>
  • trunk/src/core/net/sf/basedb/core/Annotation.java

    r6926 r6937  
    2323package net.sf.basedb.core;
    2424
     25import net.sf.basedb.core.Transactional.Action;
    2526import net.sf.basedb.core.data.AnnotationData;
    2627import net.sf.basedb.core.data.AnnotationTypeData;
     
    218219    super.initPermissions(granted, denied);
    219220  }
     221 
     222  /**
     223    Nullify links to this annotation from cloned annotations when this annotation is deleted
     224    (since the cloned annotation should not be deleted).
     225  */
     226  @Override
     227  void onBeforeCommit(Action action)
     228    throws BaseException
     229  {
     230    super.onBeforeCommit(action);
     231    if (action == Action.DELETE && getSource() == Annotation.Source.PRIMARY)
     232    {
     233      org.hibernate.Session session = getDbControl().getHibernateSession();
     234      org.hibernate.Query query = HibernateUtil.getPredefinedQuery(session,
     235        "NULLIFY_LINK_FROM_CLONES");
     236      /*
     237        UPDATE AnnotationData ad
     238        SET ad.inheritedFrom = null
     239        WHERE ad.inheritedFrom = :targetId
     240        AND ad.source = CLONED
     241      */
     242      query.setInteger("targetId", getId());
     243      HibernateUtil.executeUpdate(query);
     244    }
     245  }
     246
    220247  @Override
    221248  PluginPermission getPluginPermissions()
  • trunk/src/core/net/sf/basedb/core/AnnotationSet.java

    r6926 r6937  
    855855 
    856856  /**
    857     Remove an inherited an annotation.
     857    Remove an inherited an annotation. The specified annotation can be
     858    either a CLONED or INHERITED annotation in this set or the PRIMARY
     859    annotation of another annotation set that is inherited/cloned by
     860    this set.
     861   
    858862    @param annotation The annotation to remove
    859863    @throws PermissionDeniedException If the logged in user
     
    870874    AnnotationData toRemove = annotation.getData();
    871875    Iterator<AnnotationData> it = getData().getAnnotations().iterator();
     876    boolean checkInherited = annotation.getSource() == Annotation.Source.PRIMARY;
     877   
    872878    while (it.hasNext())
    873879    {
    874880      AnnotationData ad = it.next();
    875       if (toRemove.equals(ad.getInheritedFrom()))
     881      boolean remove = checkInherited ? toRemove.equals(ad.getInheritedFrom()) : toRemove.equals(ad);
     882      if (remove)
    876883      {
    877884        Annotation a = dc.getItem(Annotation.class, ad);
  • trunk/src/core/net/sf/basedb/core/snapshot/AnnotationSnapshot.java

    r6922 r6937  
    127127  public boolean isInherited()
    128128  {
    129     return inheritedFromId != 0;
     129    return getSource() != Annotation.Source.PRIMARY;
    130130  }
    131131 
     
    605605  {
    606606    this.inheritedFrom = inheritedFrom;
     607    if (inheritedFrom == null)
     608    {
     609      this.inheritedFromId = 0;
     610      this.inheritedFromSetId = 0;
     611    }
    607612  }
    608613
  • trunk/src/core/net/sf/basedb/core/snapshot/SnapshotManager.java

    r6922 r6937  
    198198        {
    199199          shot.setItem(snapshot.getItemId(), snapshot.getItemType());
    200           result.add(shot);
    201200         
    202201          AnnotationSetSnapshot recursive = getSnapshot(dc, shot.getInheritedAnnotationSetId());
     202          AnnotationSnapshot inheritedFrom = null;
    203203          if (recursive != null)
    204204          {
     
    211211            if (primary.size() > 0)
    212212            {
    213               shot.setInheritedFrom(primary.get(0));
     213              inheritedFrom = primary.get(0);
    214214            }
     215          }
     216          shot.setInheritedFrom(inheritedFrom);
     217          if (inheritedFrom != null || shot.getSource() == Annotation.Source.CLONED)
     218          {
     219            result.add(shot);
    215220          }
    216221        }
  • trunk/src/core/net/sf/basedb/util/annotations/InheritAnnotationsManager.java

    r6926 r6937  
    9999      for (AnnotationSnapshot inherited : snapshotManager.findAnnotations(dc, snapshot, removeFilter, false, true))
    100100      {
    101         as.removeInheritedAnnotation(inherited.getInheritedAnnotation(dc));
     101        as.removeInheritedAnnotation(inherited.getThisAnnotation(dc));
    102102      }
    103103     
     
    155155                    {
    156156                      // We only remove the annotation if it is not the same we are going to add later
    157                       as.removeInheritedAnnotation(e.getInheritedAnnotation(dc));
     157                      as.removeInheritedAnnotation(e.getThisAnnotation(dc));
    158158                    }
    159159                    else
  • trunk/www/common/annotations/inherit.jsp

    r6912 r6937  
    246246  final AnnotationSet as = item != null && item.isAnnotated() ? item.getAnnotationSet() : null;
    247247  Set<Annotation> inheritedAnnotations = null;
     248 
    248249  if (as != null)
    249250  {
    250     ItemQuery<Annotation> inheritedQuery = as.getInheritedAnnotations();
     251    ItemQuery<Annotation> inheritedQuery = as.getAnnotations(null);
     252    inheritedQuery.restrict(
     253        Restrictions.neq(
     254          Hql.property("source"),
     255          Expressions.integer(Annotation.Source.PRIMARY.ordinal())
     256      ));
     257   
    251258    inheritedQuery.order(Orders.asc(Hql.property("annotationSet")));
    252259    inheritedQuery.order(Orders.asc(Hql.property("annotationType.name")));
    253     inheritedAnnotations = new HashSet<Annotation>(inheritedQuery.list(dc));
    254     for (Annotation a : inheritedAnnotations)
    255     {
    256       AnnotationSet from = a.getAnnotationSet();
    257       if (!parentAnnotations.contains(from) && from.hasPermission(Permission.USE))
    258       {
    259         parentAnnotations.add(from);
    260         nonParents.add(from);
     260    inheritedAnnotations = new HashSet<Annotation>();
     261    for (Annotation a : inheritedQuery.list(dc))
     262    {
     263      a = a.getInheritedFrom();
     264      if (a != null)
     265      {
     266        inheritedAnnotations.add(a);
     267        AnnotationSet from = a.getAnnotationSet();
     268        if (!parentAnnotations.contains(from) && from.hasPermission(Permission.USE))
     269        {
     270          parentAnnotations.add(from);
     271          nonParents.add(from);
     272        }
    261273      }
    262274    }
  • trunk/www/common/annotations/list_annotations.jsp

    r6922 r6937  
    119119    {
    120120      AnnotationType at = a.getAnnotationType(dc);
    121       if (!a.isInherited())
     121      if (a.getSource() == Annotation.Source.PRIMARY)
    122122      {
    123123        existing.put(a.getAnnotationType(dc), a);
     
    470470          />
    471471          <tbl:columndef
     472            id="values"
     473            title="Values"
     474          />
     475          <tbl:columndef
    472476            id="source"
    473477            title="Cloned"
     
    476480            id="item"
    477481            title="From item"
    478           />
    479           <tbl:columndef
    480             id="values"
    481             title="Values"
    482482          />
    483483          <tbl:columndef
Note: See TracChangeset for help on using the changeset viewer.