Changeset 6940


Ignore:
Timestamp:
Aug 28, 2015, 2:56:06 PM (6 years ago)
Author:
Nicklas Nordborg
Message:

References #1941: Store experimental factor values as part experiments

The AnnotationSet.copyFrom() method should now be working again.

File:
1 edited

Legend:

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

    r6937 r6940  
    2626import java.util.Collection;
    2727import java.util.Collections;
     28import java.util.Date;
    2829import java.util.HashMap;
    2930import java.util.HashSet;
     
    993994    Get a query that returns inherited annotations in this annotation set.
    994995   
    995     TODO - #1941 maybe replace with a different method
    996    
    997996    @see #inheritAnnotation(Annotation)
    998997    @return An <code>ItemQuery</code> object
    999998    @throws BaseException If getting the query fails.
    1000999    @deprecated In 3.6, use {@link #getAnnotations(net.sf.basedb.core.Annotation.Source)} instead
    1001       but not that you need to navigate {@link Annotation#getInheritedFrom()} to get
     1000      but note that you need to navigate {@link Annotation#getInheritedFrom()} to get
    10021001      the same result
    10031002  */
     
    12131212    checkPermission(Permission.WRITE);
    12141213    if (!item.isAnnotated()) return;
    1215     AnnotationSet fromAs = item.getAnnotationSet();
    1216     Item toType = this.getItemType();
     1214
    12171215    DbControl dc = getDbControl();
    1218     /*
    1219     TODO - #1941
    1220    
    1221     Map<AnnotationTypeData, AnnotationData> toAnnotations = this.getData().getAnnotations();
    1222     Map<AnnotationTypeData, AnnotationData> fromAnnotations = fromAs.getData().getAnnotations();
    1223    
    1224     for (Map.Entry<AnnotationTypeData, AnnotationData> entry : fromAnnotations.entrySet())
    1225     {
    1226       AnnotationTypeData at = entry.getKey();
     1216
     1217    // Build map of current primary annotations
     1218    int primary = Annotation.Source.PRIMARY.ordinal();
     1219    Map<AnnotationTypeData, AnnotationData> currentAnnotations = new HashMap<AnnotationTypeData, AnnotationData>();
     1220    for (AnnotationData a : getData().getAnnotations())
     1221    {
     1222      if (a.getSource() != primary) continue; // Skip non-PRIMARY annotations
     1223
     1224      currentAnnotations.put(a.getAnnotationType(), a);
     1225    }
     1226   
     1227    int targetItem = getItemType().getValue();
     1228    for (AnnotationData from : item.getAnnotationSet().getData().getAnnotations())
     1229    {
     1230      // Skip non-PRIMARY annotations
     1231      if (from.getSource() != primary) continue;
     1232     
    12271233      // Check if the target item can hold annotation of this type
    1228       if (at.getItemTypes().contains(toType.getValue()))
    1229       {
    1230         AnnotationData to = null;
    1231         if (toAnnotations.containsKey(at))
    1232         {         
    1233           // Use existing entry unless overwrite == false
    1234           if (!overwrite)
    1235           {
    1236             // #### CONTINUE-STATEMENT ####
    1237             continue;
    1238           }
    1239           to = toAnnotations.get(at);
    1240         }
    1241         else
    1242         {
    1243           // Create new annotation
    1244           Type valueType = Type.fromValue(at.getValueType());
    1245           to = new AnnotationData();
    1246           to.setAnnotationSet(this.getData());
    1247           to.setAnnotationType(at);
    1248           to.setValues(valueType.newParameterValueData());
    1249           toAnnotations.put(at, to);
    1250           Annotation newAnnotation = new Annotation(to, this);
    1251           newAnnotation.disableATPermissionCheck();
    1252           dc.saveItemIf(this, newAnnotation, false);
    1253         }
    1254         // Copy the values
    1255         AnnotationData from = entry.getValue();
    1256         to.getValues().replaceValues(from.getValues().getValues());
    1257         to.setLastUpdate(new Date());
    1258         setSnapshotInvalid();
    1259       }
    1260     }
    1261     */
     1234      AnnotationTypeData at = from.getAnnotationType();
     1235      if (!at.getItemTypes().contains(targetItem)) continue;
     1236     
     1237      // Check if there is an existing annotation and skip if it should not overwrite
     1238      AnnotationData current = currentAnnotations.get(at);
     1239      if (current != null && !overwrite) continue;
     1240     
     1241      if (current == null)
     1242      {
     1243        // Create new annotation
     1244        Type valueType = Type.fromValue(at.getValueType());
     1245        current = new AnnotationData();
     1246        current.setAnnotationSet(this.getData());
     1247        current.setAnnotationType(at);
     1248        current.setValues(valueType.newParameterValueData());       
     1249        current.setSource(primary);
     1250       
     1251        currentAnnotations.put(at, current);
     1252        Annotation newAnnotation = new Annotation(current, this);
     1253        newAnnotation.disableATPermissionCheck();
     1254        dc.saveItemIf(this, newAnnotation, false);
     1255      }
     1256     
     1257      // Copy the values
     1258      current.getValues().replaceValues(from.getValues().getValues());
     1259      current.setUnit(from.getUnit());
     1260      current.setLastUpdate(new Date());
     1261      setSnapshotInvalid();
     1262    }
     1263   
    12621264  }
    12631265 
Note: See TracChangeset for help on using the changeset viewer.