Changeset 3804


Ignore:
Timestamp:
Oct 4, 2007, 2:25:41 PM (16 years ago)
Author:
Nicklas Nordborg
Message:

References #721: Most things for attaching files to array designs are now in place.

  • Added update script for updating existing installations
  • Re-coded parts of the code that depended on depracated methods
  • Changed depracated methods to be backwards compatible
  • Plugins that import to or use array designs can now use the attached files
Location:
branches/filedb
Files:
1 added
14 edited

Legend:

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

    r3797 r3804  
    28572857    </description>
    28582858  </query>
     2859 
     2860  <query id="GET_FILESETMEMBER_FOR_DATAFILETYPE" type="HQL">
     2861    <sql>
     2862      SELECT mbr
     2863      FROM FileSetMemberData mbr
     2864      WHERE mbr.dataFileType.externalId = :externalId
     2865      AND mbr.fileSet = :fileSet
     2866    </sql>
     2867    <description>
     2868      A Hibernate query that loads a member in a given file set
     2869      if we know the external ID of the data file type.
     2870    </description>
     2871  </query>
     2872
     2873 
     2874  <query id="DELETE_PROPERTY_FILTER" type="SQL">
     2875    <sql>
     2876      DELETE FROM [PropertyFilters]
     2877      WHERE [property] = :property
     2878    </sql>
     2879    <description>
     2880      An SQL query that delete all PropertyFilters
     2881      which filter on a given property.
     2882    </description>
     2883  </query>
     2884 
     2885  <query id="GET_PLUGINS_WITH_KEYS" type="HQL">
     2886    <sql>
     2887      SELECT DISTINCT pk.pluginDefinitionId
     2888      FROM PluginKeys pk WHERE pk.keyId IN (:keys)
     2889    </sql>
     2890    <description>
     2891      A HQL query that has been granted a specific permission. Used by
     2892      update scripts when new item types are added to make sure existing
     2893      plug-ins can continue to work.
     2894    </description>
     2895  </query>
    28592896
    28602897
  • branches/filedb/src/core/net/sf/basedb/core/Affymetrix.java

    r3802 r3804  
    7979      Affymetrix chip or if the file is not a CDF file
    8080    @throws BaseException If there is another error
    81     @deprecated
     81    @deprecated Use {@link FileStoreUtil#setDataFile(DbControl, FileStoreEnabled, String, File)}
     82      instead with {@link DataFileType#AFFYMETRIX_CDF} as the file
     83      type
    8284  */
    8385  public static void setCdfFile(ArrayDesign design, File file)
     
    8587  {
    8688    if (design == null) throw new InvalidUseOfNullException("design");
    87     if (!design.isAffyChip())
     89    if (!design.isPlatform(Platform.AFFYMETRIX))
    8890    {
    8991      throw new InvalidDataException("Array design isn't an Affymetrix chip: " + design);
    9092    }
    91     design.checkPermission(Permission.WRITE);
    9293    DbControl dc = design.getDbControl();
    93     if (file != null)
    94     {
    95       file.checkPermission(Permission.USE);
    96      
    97       // Verify that the file is a CDF file
    98       FusionCDFData cdf = loadCdfFile(file);
    99    
    100       AnyToAny ata = AnyToAny.getNewOrExisting(dc, design, CDF_LINK_NAME, file, true);
    101       if (!ata.isInDatabase()) dc.saveItem(ata);
    102       design.getData().setHasFeatures(true);
    103       design.getData().setNumFileFeatures(cdf.getHeader().getNumProbeSets());
    104     }
    105     else
    106     {
    107       AnyToAny.unlinkFrom(dc, design, CDF_LINK_NAME);
    108       design.getData().setHasFeatures(false);
    109     }
     94    FileStoreUtil.setDataFile(dc, design, DataFileType.AFFYMETRIX_CDF, file);
     95    if (file != null) design.getFileSet().validate(dc, true);
    11096  }
    11197 
     
    131117      Affymetrix chip
    132118    @throws BaseException If there is another error
    133     @deprecated Use {@link FileSet#getMember(DataFileType)}
     119    @deprecated Use {@link FileStoreUtil#getDataFile(DbControl, FileStoreEnabled, String)}
    134120      with a data file type of {@link DataFileType#AFFYMETRIX_CDF}
    135121      instead
     
    139125  {
    140126    if (design == null) throw new InvalidUseOfNullException("design");
    141     if (!design.isAffyChip())
    142     {
    143       throw new InvalidDataException("Array design isn't an Affymetrix chip: " + design);
     127    if (!design.isPlatform(Platform.AFFYMETRIX))
     128    {
     129      throw new InvalidDataException("Array design isn't an Affymetrix chip: " + design.getName());
    144130    }
    145131    DbControl dc = design.getDbControl();
    146     File cdfFile = null;
    147     if (design.hasFileSet())
    148     {
    149       FileSet fileSet = design.getFileSet();
    150       DataFileType cdfType = DataFileType.getByExternalId(dc, DataFileType.AFFYMETRIX_CDF);
    151       if (fileSet.hasMember(cdfType))
    152       {
    153         FileSetMember member = fileSet.getMember(cdfType);
    154         cdfFile = member.getFile();
    155       }
    156     }
    157     return cdfFile;
     132    return FileStoreUtil.getDataFile(dc, design, DataFileType.AFFYMETRIX_CDF);
    158133  }
    159134
     
    211186          " must have an array design to set CEL file");
    212187      }
    213       if (!design.isAffyChip())
     188      if (!design.isPlatform(Platform.AFFYMETRIX))
    214189      {
    215190        throw new InvalidDataException("The array design " + design.getName() +
  • branches/filedb/src/core/net/sf/basedb/core/ArrayDesign.java

    r3802 r3804  
    8989  }
    9090
     91  /**
     92    Create a new <code>ArrayDesign</code> item for a given platform.
     93 
     94    @param dc The <code>DbControl</code> which will be used for
     95      permission checking and database access
     96    @param platform The platform of the array design
     97    @return The new <code>ArrayDesign</code> item
     98    @throws BaseException If there is an error
     99  */
    91100  public static ArrayDesign getNew(DbControl dc, Platform platform)
    92101  {
     
    97106  }
    98107
     108  /**
     109    Create a new <code>ArrayDesign</code> item for a given platform
     110    variant.
     111 
     112    @param dc The <code>DbControl</code> which will be used for
     113      permission checking and database access
     114    @param variant The platform variant of the array design
     115    @return The new <code>ArrayDesign</code> item
     116    @throws BaseException If there is an error
     117  */
    99118  public static ArrayDesign getNew(DbControl dc, PlatformVariant variant)
    100119  {
     
    104123    return ad;
    105124  }
    106  
    107125 
    108126  /**
     
    273291  // -------------------------------------------
    274292 
     293  /**
     294    Set the platform of the array design. This method will set the variant
     295    to null. Use {@link #setVariant(PlatformVariant)} if you want to
     296    set a specific variant.
     297    @param platform The new platform
     298    @throws PermissionDeniedException If the logged in user doesn't have
     299      write permission
     300    @throws InvalidDataException If platform is null
     301  */
    275302  public void setPlatform(Platform platform)
    276303  {
     
    281308  }
    282309 
     310  /**
     311    Set the platform and variant of the array design. This method will
     312    automatically set the platform to {@link PlatformVariant#getPlatform()}.
     313
     314    @param variant The new platform variant, or null to remove
     315      the variant and keep the platform as it is
     316    @throws PermissionDeniedException If the logged in user doesn't have
     317      write permission
     318  */
    283319  public void setVariant(PlatformVariant variant)
    284320  {
     
    296332 
    297333  /**
    298       @return TRUE if this is an AffyChip, FALSE otherwise.
    299       @deprecated Use {@link #getPlatform()} instead and compare the
    300         external ID with {@link Platform#AFFYMETRIX}
     334    Check if the platform/variant of this array design has the
     335    given external ID.
     336    @param externalId The external ID to match
     337    @return TRUE if either the variant of platform matches the
     338      external ID
     339  */
     340  public boolean isPlatform(String externalId)
     341  {
     342    if (externalId == null) return false;
     343    if (externalId.equals(getData().getPlatform().getExternalId())) return true;
     344    if (getData().getVariant() != null)
     345    {
     346      if (externalId.equals(getData().getVariant().getExternalId())) return true;
     347    }
     348    return false;
     349  }
     350 
     351  /**
     352    Check if this array design uses a file-only platform or variant.
     353    If the array design has a platform variant, the setting from the
     354    variant is returned, otherwise the setting from the platform.
     355    @return TRUE if this array design use a file-only platform
     356  */
     357  public boolean isFileOnlyPlatform()
     358  {
     359    if (getData().getVariant() != null)
     360    {
     361      return getData().getVariant().isFileOnly();
     362    }
     363    else
     364    {
     365      return getData().getPlatform().isFileOnly();
     366    }
     367  }
     368 
     369  /**
     370      @return TRUE if this is an Affymetrix chip, FALSE otherwise.
     371      @deprecated Use {@link #isPlatform(String)} instead with
     372        {@link Platform#AFFYMETRIX} as the parameter
    301373  */
    302374  public boolean isAffyChip()
    303375  {
    304     return Platform.AFFYMETRIX.equals(getData().getPlatform().getExternalId());
    305   }
    306 
    307   /**
     376    return isPlatform(Platform.AFFYMETRIX);
     377  }
     378
     379  /**
     380    Check if this array design has information about features, either
     381    in the database or in files.
    308382      @return TRUE if this object has features, FALSE otherwise
    309383  */
     
    491565    that can add features to the new block.
    492566    <p>
    493     It is not possible to add blocks to an Affymetrix chip. It stores
    494     it's feature in a CDF file instead. See {@link Affymetrix#setCdfFile(ArrayDesign, File)}.
     567    It is not possible to add blocks to an array design which uses a
     568    file-only platform. The must store feature information in files
     569    instead. See {@link Platform} and {@link DataFileType}.
    495570
    496571    @param bi The information for the new block
     
    503578    throws PermissionDeniedException, BaseException
    504579  {
     580    if (getData().getPlatform().isFileOnly())
     581    {
     582      throw new PermissionDeniedException("Can't add blocks to a file-only array design: " + this.getName());
     583    }
    505584    if (hasFeatures())
    506585    {
    507       throw new PermissionDeniedException("Can't add blocks to a design that already has features: " + this);
    508     }
    509     if (isAffyChip())
    510     {
    511       throw new PermissionDeniedException("Can't add blocks to an Affymetrix chip: " + this);
     586      throw new PermissionDeniedException("Can't add blocks to a design that already has features: " + this.getName());
    512587    }
    513588    checkPermission(Permission.WRITE);
     
    531606    array design.   
    532607    <p>
    533     It is not possible to add features to an Affymetrix chip. It stores
    534     it's feature in a CDF file instead. See {@link Affymetrix#setCdfFile(ArrayDesign, File)}.
     608    It is not possible to add blocks to an array design which uses a
     609    file-only platform. The must store feature information in files
     610    instead. See {@link Platform} and {@link DataFileType}.
    535611
    536612    @throws PermissionDeniedException If raw data has already been added
     
    542618  {
    543619    checkPermission(Permission.WRITE);
     620    if (isFileOnlyPlatform())
     621    {
     622      throw new PermissionDeniedException("Can't add features to a file-only array design: " + this.getName());
     623    }
    544624    if (hasFeatures())
    545625    {
    546       throw new PermissionDeniedException("Features has already been added to "+this);
    547     }
    548     if (isAffyChip())
    549     {
    550       throw new PermissionDeniedException("Can't add features to an Affymetrix chip: " + this);
     626      throw new PermissionDeniedException("Features has already been added to "+this.getName());
    551627    }
    552628    if (featureBatcher == null)
  • branches/filedb/src/core/net/sf/basedb/core/FeatureBatcher.java

    r3783 r3804  
    7777 
    7878  /**
    79     If the array design is an affy chip which needs AffyFeatureData
    80     objects instead of FeatureData.
    81   */
    82   private final boolean isAffy;
    83 
    84  
    85   /**
    8679    Keeps track of the position number.
    8780  */
     
    9487    this.arrayDesign = arrayDesign;
    9588    this.arrayDesignData = arrayDesign.getData();
    96     this.isAffy = arrayDesign.isAffyChip();
    9789    setDbControl(dc);
    9890  }
     
    209201    throws BaseException
    210202  {
    211     if (getTotalInsertCount() > 0)
     203    int insertCount = getTotalInsertCount();
     204    if (insertCount > 0)
    212205    {
    213206      arrayDesignData.setHasFeatures(true);
     207      arrayDesignData.setNumDbFeatures(insertCount);
    214208    }
    215209  }
  • branches/filedb/src/core/net/sf/basedb/core/FileSet.java

    r3802 r3804  
    255255  }
    256256 
     257  public ItemQuery<FileSetMember> getMembers(String genericType)
     258  {
     259    ItemQuery<FileSetMember> query = getMembers();
     260    query.restrictPermanent(
     261      Restrictions.eq(
     262        Hql.property("dataFileType.genericType.systemId"),
     263        Expressions.string(genericType)
     264      )
     265    );
     266    return query;
     267  }
     268 
    257269  /**
    258270    Set a file of a given type as a member of this file set.
    259271    If another file of the given type already exists, it is replaced
    260272    with this file. If no member exists, a new entry is created and
    261     automaticall saved to the database when {@link DbControl#commit()}
     273    automatically saved to the database when {@link DbControl#commit()}
    262274    is called.
    263275    @param file The file to set as a member
    264276    @param type The type of the file
     277    @return The new FileSetMember item
    265278    @throws InvalidUseOfNullException If file or type is null
    266279    @throws PermissionDeniedException If the logged in user doesn't
     
    268281      file
    269282  */
    270   public void setMember(File file, DataFileType type)
     283  public FileSetMember setMember(File file, DataFileType type)
    271284  {
    272285    checkPermission(Permission.WRITE);
     
    276289   
    277290    Map<DataFileTypeData, FileSetMemberData> members = getData().getMembers();
    278     FileSetMemberData member = members.get(type.getData());
    279     if (member == null)
    280     {
    281       FileSetMember newMember = FileSetMember.getNew(getDbControl(), this, file, type);
    282       members.put(type.getData(), newMember.getData());
    283       getDbControl().saveItemIf(this, newMember, false);
     291    FileSetMemberData memberData = members.get(type.getData());
     292    FileSetMember member = null;
     293    if (memberData == null)
     294    {
     295      member = FileSetMember.getNew(getDbControl(), this, file, type);
     296      members.put(type.getData(), member.getData());
     297      getDbControl().saveItemIf(this, member, false);
    284298    }
    285299    else
    286300    {
    287       if (!file.getData().equals(member.getFile()))
    288       {
    289         member.setFile(file.getData());
    290         member.setValid(null);
    291       }
    292     }
     301      if (!file.getData().equals(memberData.getFile()))
     302      {
     303        memberData.setFile(file.getData());
     304        memberData.setValid(null);
     305      }
     306      member = getDbControl().getItem(FileSetMember.class, memberData);
     307    }
     308    return member;
    293309  }
    294310 
  • branches/filedb/src/core/net/sf/basedb/core/FileSetMember.java

    r3802 r3804  
    195195  }
    196196 
     197  public void setValid(Boolean valid, String errorMessage)
     198  {
     199    checkPermission(Permission.WRITE);
     200    getData().setValid(valid);
     201    getData().setErrorMessage(errorMessage);
     202  }
     203 
    197204  /**
    198205    Get the error message if the validation failed.
  • branches/filedb/src/core/net/sf/basedb/core/Install.java

    r3801 r3804  
    107107    method.
    108108  */
    109   public static final int NEW_SCHEMA_VERSION = Integer.valueOf(43).intValue();
     109  public static final int NEW_SCHEMA_VERSION = Integer.valueOf(44).intValue();
    110110 
    111111  public static synchronized void createTables(boolean update, final ProgressReporter progress)
  • branches/filedb/src/core/net/sf/basedb/core/RawBioAssay.java

    r3783 r3804  
    349349  // -------------------------------------------
    350350
    351   private void setPlatform(Platform platform)
    352   {
     351  public void setPlatform(Platform platform)
     352  {
     353    checkPermission(Permission.WRITE);
    353354    if (platform == null) throw new InvalidUseOfNullException("platform");
    354355    getData().setPlatform(platform.getData());
    355   }
    356  
    357   private void setVariant(PlatformVariant variant)
    358   {
    359     if (variant == null) throw new InvalidUseOfNullException("variant");
    360     getData().setVariant(variant.getData());
    361   }
     356    getData().setVariant(null);
     357  }
     358 
     359  public void setVariant(PlatformVariant variant)
     360  {
     361    checkPermission(Permission.WRITE);
     362    if (variant != null)
     363    {
     364      getData().setVariant(variant.getData());
     365      getData().setPlatform(variant.getData().getPlatform());
     366    }
     367    else
     368    {
     369      getData().setVariant(null);
     370    }
     371  }
    362372 
    363373  /**
  • branches/filedb/src/core/net/sf/basedb/core/Update.java

    r3801 r3804  
    2929import java.sql.SQLException;
    3030import java.sql.Statement;
     31import java.util.Arrays;
    3132import java.util.Collections;
    3233import java.util.Date;
     
    3940import org.hibernate.mapping.Table;
    4041
    41 import affymetrix.fusion.cdf.FusionCDFData;
    42 
    43 import net.sf.basedb.core.data.AnyToAnyData;
    4442import net.sf.basedb.core.data.ArrayDesignData;
    4543import net.sf.basedb.core.data.DataCubeData;
     
    5351import net.sf.basedb.core.data.PluginConfigurationData;
    5452import net.sf.basedb.core.data.PluginDefinitionData;
     53import net.sf.basedb.core.data.RawBioAssayData;
    5554import net.sf.basedb.core.data.SchemaVersionData;
    5655import net.sf.basedb.core.data.TransformationData;
     56import net.sf.basedb.core.data.keyring.PluginKeys;
    5757import net.sf.basedb.core.dbengine.DbEngine;
    5858import net.sf.basedb.core.dbengine.TableInfo;
     
    491491    </td>
    492492  </tr>
    493 
     493 
    494494  <tr>
    495495    <td>42</td>
    496496    <td>
    497       <ul>
    498       <li>Added {@link net.sf.basedb.core.data.ArrayDesignData#getNumFeatures()}
    499       </ul>
    500       The update will query the database or check the CDF file to get
    501       the information.
    502     </td>
    503   </tr>
    504  
     497      No longer used.
     498    </td>
     499  </tr>
     500
    505501  <tr>
    506502    <td>43</td>
     
    511507    </td>
    512508  </tr>
     509
     510  <tr>
     511    <td>44</td>
     512    <td>
     513      <ul>
     514      <li>Added {@link Platform}, {@link DataFileType} and
     515        a lot of related classes.
     516      </ul>
     517      The update will set a platform for all array designs and
     518      raw bioassays. For Affymetrix data it will move the CEL and CDF files
     519      from AnyToAny links into FileSet:s.
     520    </td>
     521  </tr>
     522
    513523
    514524  </table>
     
    726736      }
    727737
    728       /*
    729       if (schemaVersion < 43)
    730       {
    731         if (progress != null) progress.display((int)(42*progress_factor), "--Updating schema version: " + schemaVersion + " -> 43...");
    732         schemaVersion = setSchemaVersionInTransaction(session, 43);
    733         - or -
    734         schemaVersion = updateToSchemaVersion43(session);
    735       }
    736       ... etc...
    737       */
     738      if (schemaVersion < 44)
     739      {
     740        if (progress != null) progress.display((int)(43*progress_factor), "--Updating schema version: " + schemaVersion + " -> 44...");
     741        schemaVersion = updateToSchemaVersion44(sc);
     742      }
    738743
    739744      sc.logout();
     
    16051610
    16061611  /**
    1607     Count the number of features for all array designs. For Affymetrix designs
    1608     the CDF file is checked.
     1612    Has been replaced with {@link #updateToSchemaVersion44(SessionControl)}
    16091613    @return The new schema version (=42)
    16101614  */
     
    16121616  {
    16131617    final int schemaVersion = 42;
    1614     org.hibernate.Transaction tx = null;
    1615     try
    1616     {
    1617       tx = HibernateUtil.newTransaction(session);
    1618  
    1619       org.hibernate.Query query = HibernateUtil.createQuery(session,
    1620         "SELECT ad FROM ArrayDesignData ad");
    1621       org.hibernate.Query countQuery = HibernateUtil.getPredefinedQuery(session,
    1622         "COUNT_FEATURES_FOR_ARRAYDESIGN");
    1623       org.hibernate.Query cdfQuery = HibernateUtil.getPredefinedQuery(session,
    1624         "GET_ANYTOANY_FOR_NAME");
    1625       cdfQuery.setInteger("fromType", Item.ARRAYDESIGN.getValue());
    1626       cdfQuery.setString("name", Affymetrix.CDF_LINK_NAME);
    1627      
    1628       List<ArrayDesignData> designs = HibernateUtil.loadList(ArrayDesignData.class, query);
    1629       for (ArrayDesignData design : designs)
    1630       {
    1631         int numFeatures = -1;
    1632         try
    1633         {
    1634           if (!design.getHasFeatures())
    1635           {
    1636             numFeatures = 0;
    1637           }
    1638           else  if (design.isAffyChip())
    1639           {
    1640             // Get CDF file and the number of features
    1641             cdfQuery.setInteger("fromId", design.getId());
    1642             AnyToAnyData cdfLink = HibernateUtil.loadData(AnyToAnyData.class, cdfQuery);
    1643             FileData cdf = null;
    1644             if (cdfLink != null)
    1645             {
    1646               cdf = HibernateUtil.loadData(session, FileData.class, cdfLink.getToId());
    1647             }
    1648             if (cdf != null)
    1649             {
    1650               FusionCDFData cdfData = new FusionCDFData();
    1651               cdfData.setFileName(File.getAbsolutePath(cdf.getInternalName()).getPath());
    1652               cdfData.readHeader();
    1653               numFeatures = cdfData.getHeader().getNumProbeSets();
    1654             }
    1655             else
    1656             {
    1657               numFeatures = 0;
    1658             }
    1659           }
    1660           else
    1661           {
    1662             countQuery.setInteger("arrayDesign", design.getId());
    1663             numFeatures = HibernateUtil.loadData(Long.class, countQuery).intValue();
    1664           }
    1665         }
    1666         catch (Throwable t)
    1667         {
    1668           log.error("Could not set number of features on array design: " + design, t);
    1669         }
    1670         //design.setNumFeatures(numFeatures);
    1671       }
    1672 
    1673  
    1674       // Update the schema version number
    1675       setSchemaVersion(session, schemaVersion);
    1676  
    1677       // Commit the changes
    1678       HibernateUtil.commit(tx);
    1679       log.info("updateToSchemaVersion42: OK");
    1680     }
    1681     catch (BaseException ex)
    1682     {
    1683       if (tx != null) HibernateUtil.rollback(tx);
    1684       log.error("updateToSchemaVersion42: FAILED", ex);
    1685       throw ex;
    1686     }
    16871618    return schemaVersion;   
    16881619  }
     
    17281659  }
    17291660
     1661  /**
     1662    Set a platform for array designs and raw bioassays.
     1663    Move CEL and CDF files into FileSet:s
     1664    Remove filters on isAffyChip property
     1665  */
     1666  @SuppressWarnings("deprecation")
     1667  private static int updateToSchemaVersion44(SessionControl sc)
     1668  {
     1669    final int schemaVersion = 44;
     1670    DbControl dc = null;
     1671    try
     1672    {
     1673      dc = sc.newDbControl();
     1674      org.hibernate.Session session = dc.getHibernateSession();
     1675 
     1676      // Items that we need
     1677      Platform affymetrix = Platform.getByExternalId(dc, Platform.AFFYMETRIX);
     1678      Platform generic = Platform.getByExternalId(dc, Platform.GENERIC);
     1679      DataFileType cdfType = DataFileType.getByExternalId(dc, DataFileType.AFFYMETRIX_CDF);
     1680      DataFileType celType = DataFileType.getByExternalId(dc, DataFileType.AFFYMETRIX_CEL);
     1681     
     1682      // Query to count number of features in db
     1683      org.hibernate.Query countQuery = HibernateUtil.getPredefinedQuery(session,
     1684        "COUNT_FEATURES_FOR_ARRAYDESIGN");
     1685
     1686      // Load array designs
     1687      org.hibernate.Query designQuery = HibernateUtil.createQuery(session,
     1688        "SELECT ad FROM ArrayDesignData ad WHERE ad.platform is null");
     1689      List<ArrayDesignData> arrayDesigns =
     1690        HibernateUtil.loadList(ArrayDesignData.class, designQuery);
     1691      for (ArrayDesignData dd : arrayDesigns)
     1692      {
     1693        ArrayDesign design = dc.getItem(ArrayDesign.class, dd);
     1694        if (design.getData().isAffyChip())
     1695        {
     1696          design.setPlatform(affymetrix);
     1697          AnyToAny anyCdf = null;
     1698          try
     1699          {
     1700            anyCdf = AnyToAny.getByName(dc, design, Affymetrix.CDF_LINK_NAME);
     1701          }
     1702          catch (Throwable t)
     1703          {}
     1704          AnyToAny.unlinkFrom(dc, design, Affymetrix.CDF_LINK_NAME);
     1705          if (anyCdf != null)
     1706          {
     1707            File cdfFile = (File)anyCdf.getTo();
     1708            FileSet fileSet = design.getFileSet();
     1709            fileSet.setMember(cdfFile, cdfType);
     1710            fileSet.validate(dc, true);
     1711          }
     1712        }
     1713        else
     1714        {
     1715          design.setPlatform(generic);
     1716          countQuery.setInteger("arrayDesign", design.getId());
     1717          int dbFeatures = HibernateUtil.loadData(Long.class, countQuery).intValue();
     1718          design.getData().setNumDbFeatures(dbFeatures);
     1719        }
     1720      }
     1721     
     1722      // Load rawbioassays
     1723      org.hibernate.Query rbaQuery = HibernateUtil.createQuery(session,
     1724        "SELECT rba FROM RawBioAssayData rba WHERE rba.platform is null");
     1725      List<RawBioAssayData> rawBioAssays =
     1726        HibernateUtil.loadList(RawBioAssayData.class, rbaQuery);
     1727      for (RawBioAssayData dd : rawBioAssays)
     1728      {
     1729        RawBioAssay rba = dc.getItem(RawBioAssay.class, dd);
     1730        if ("affymetrix".equals(rba.getData().getRawDataType()))
     1731        {
     1732          rba.setPlatform(affymetrix);
     1733          AnyToAny anyCel = null;
     1734          try
     1735          {
     1736            anyCel = AnyToAny.getByName(dc, rba, Affymetrix.CEL_LINK_NAME);
     1737          }
     1738          catch (Throwable t)
     1739          {}
     1740          AnyToAny.unlinkFrom(dc, rba, Affymetrix.CEL_LINK_NAME);
     1741          if (anyCel != null)
     1742          {
     1743            File celFile = (File)anyCel.getTo();
     1744            FileSet fileSet = rba.getFileSet();
     1745            fileSet.setMember(celFile, cdfType);
     1746            fileSet.validate(dc, true);
     1747          }
     1748        }
     1749        else
     1750        {
     1751          rba.setPlatform(generic);
     1752        }
     1753      }
     1754 
     1755      // Remove filters on the 'affyChip' property
     1756      org.hibernate.Query query = HibernateUtil.getPredefinedSQLQuery(session,
     1757        "DELETE_PROPERTY_FILTER");
     1758      /*
     1759        DELETE FROM PropertyFilters pf
     1760        WHERE pf.property = :property
     1761       */
     1762      query.setString("property", "affyChip");
     1763      HibernateUtil.executeUpdate(query);
     1764
     1765      // Add READ permission to PLATFORM and DATAFILETYPE for all plug-ins
     1766      // working with ARRAYDESIGN or RAWBIOASSAY
     1767      int adKeyId = SystemItems.getRoleKeyId(Item.ARRAYDESIGN);
     1768      int rbaKeyId = SystemItems.getRoleKeyId(Item.RAWBIOASSAY);
     1769     
     1770      org.hibernate.Query pQuery = HibernateUtil.getPredefinedQuery(session,
     1771        "GET_PLUGINS_WITH_KEYS");
     1772      /*
     1773        SELECT DISTINCT pk.pluginDefinitionId
     1774        FROM PluginKeys pk WHERE pk.keyId IN (:keys)
     1775      */
     1776      pQuery.setParameterList("keys",
     1777        Arrays.asList( new Integer[] { adKeyId, rbaKeyId }), Type.INT.getHibernateType());
     1778      List<Integer> pluginIds = HibernateUtil.loadList(Integer.class, pQuery);
     1779      for (int pluginId : pluginIds)
     1780      {
     1781        addPluginPermission(session, pluginId, Item.PLATFORM, 0, 2046);
     1782        addPluginPermission(session, pluginId, Item.DATAFILETYPE, 0, 2046);
     1783      }
     1784     
     1785      // Update the schema version number
     1786      setSchemaVersion(session, schemaVersion);
     1787 
     1788      // Commit the changes
     1789      dc.commit();
     1790      log.info("updateToSchemaVersion44: OK");
     1791    }
     1792    catch (BaseException ex)
     1793    {
     1794      log.error("updateToSchemaVersion44: FAILED", ex);
     1795      throw ex;
     1796    }
     1797    finally
     1798    {
     1799      if (dc != null) dc.close();
     1800    }
     1801    return schemaVersion;   
     1802  }
     1803
     1804  private static void addPluginPermission(org.hibernate.Session session, int pluginId, Item itemType, int granted, int denied)
     1805  {
     1806    PluginKeys pk = new PluginKeys();
     1807    pk.setPluginDefinitionId(pluginId);
     1808    pk.setKeyId(SystemItems.getRoleKeyId(itemType));
     1809    if (session.get(PluginKeys.class, pk) == null)
     1810    {
     1811      pk.setGranted(granted);
     1812      pk.setDenied(denied);
     1813      session.save(pk);
     1814    }
     1815  }
     1816 
    17301817  /**
    17311818    Adjust the existing items in the database to be compatible with the latest mappings.
  • branches/filedb/src/plugins/core/net/sf/basedb/plugins/CdfFileReporterImporter.java

    r3675 r3804  
    4545import net.sf.basedb.core.ArrayDesign;
    4646import net.sf.basedb.core.BaseException;
     47import net.sf.basedb.core.DataFileType;
    4748import net.sf.basedb.core.DbControl;
    4849import net.sf.basedb.core.File;
    4950import net.sf.basedb.core.FileParameterType;
     51import net.sf.basedb.core.FileStoreUtil;
    5052import net.sf.basedb.core.InvalidDataException;
    5153import net.sf.basedb.core.Item;
     
    5759import net.sf.basedb.core.Operator;
    5860import net.sf.basedb.core.Permission;
     61import net.sf.basedb.core.Platform;
    5962import net.sf.basedb.core.PluginParameter;
    6063import net.sf.basedb.core.ProgressReporter;
     
    6568import net.sf.basedb.core.StringParameterType;
    6669import net.sf.basedb.core.Type;
     70import net.sf.basedb.core.filehandler.CdfFileHandler;
    6771import net.sf.basedb.core.plugin.About;
    6872import net.sf.basedb.core.plugin.AboutImpl;
     
    156160  /**
    157161    Request create and write access to Reporter:s
    158     and read access to File:s ArrayDesign:s and ReporterType:s.
     162    and read access to File:s ArrayDesign:s, ReporterType:s,
     163    Platform:s and DataFileType:s
    159164  */
    160165  public Collection<Permissions> getPermissions()
     
    166171      permissions.add(new Permissions(Item.FILE, null, EnumSet.of(Permission.READ)));
    167172      permissions.add(new Permissions(Item.ARRAYDESIGN, null, EnumSet.of(Permission.READ)));
     173      permissions.add(new Permissions(Item.PLATFORM, null, EnumSet.of(Permission.READ)));
     174      permissions.add(new Permissions(Item.DATAFILETYPE, null, EnumSet.of(Permission.READ)));
    168175    }
    169176    return permissions;
     
    178185      File cdfFile = (File)job.getValue("file");
    179186      cdfFile = File.getById(dc, cdfFile.getId());
    180       FusionCDFData cdf = Affymetrix.loadCdfFile(cdfFile);
     187      FusionCDFData cdf = new CdfFileHandler().loadCdfFile(cdfFile);
    181188 
    182189      // Import data from it
     
    225232      }
    226233      ArrayDesign design = (ArrayDesign)item;
    227       if (!design.isAffyChip())
     234      if (!design.isPlatform(Platform.AFFYMETRIX))
    228235      {
    229236        message = "The array design is not an Affymetrix chip";
     
    231238      else
    232239      {
    233         File cdfFile = Affymetrix.getCdfFile(design);
    234         if (cdfFile == null)
    235         {
    236           throw new InvalidDataException("The array design doesn't have a CDF file");
     240        if (!FileStoreUtil.hasDataFile(design.getDbControl(), design, DataFileType.AFFYMETRIX_CDF, true))
     241        {
     242          throw new InvalidDataException("The array design doesn't have a valid CDF file");
    237243        }
    238244      }
     
    274280        // Verify that the file is a CDF file
    275281        File cdfFile = (File)request.getParameterValue("file");
    276         FusionCDFData cdf = Affymetrix.loadCdfFile(cdfFile);
     282        FusionCDFData cdf = new CdfFileHandler().loadCdfFile(cdfFile);
    277283       
    278284        storeValue(job, request, ri.getParameter("file"));
     
    383389          int currentArrayDesignId = sc.getCurrentContext(Item.ARRAYDESIGN).getId();
    384390          design = ArrayDesign.getById(dc, currentArrayDesignId);
    385           cdfFile = Affymetrix.getCdfFile(design);
     391          cdfFile = FileStoreUtil.getDataFile(dc, design, DataFileType.AFFYMETRIX_CDF);
    386392          presets = Arrays.asList(new File[] { cdfFile } );
    387393        }
  • branches/filedb/src/plugins/core/net/sf/basedb/plugins/PrintMapFlatFileImporter.java

    r3679 r3804  
    3232import net.sf.basedb.core.DbControl;
    3333import net.sf.basedb.core.FeatureBatcher;
     34import net.sf.basedb.core.File;
     35import net.sf.basedb.core.FileParameterType;
     36import net.sf.basedb.core.FileSetMember;
     37import net.sf.basedb.core.FileStoreUtil;
    3438import net.sf.basedb.core.FileType;
    3539import net.sf.basedb.core.IntegerUtil;
     
    122126
    123127  private ArrayDesign arrayDesign;
     128  private FileSetMember printMapMember;
    124129  private ItemParameterType<ArrayDesign> arrayDesignType;
    125130  private PluginParameter<ArrayDesign> arrayDesignParameter;
     
    150155  }
    151156  /**
    152     Request write access to ArrayDesign:s, read access to Plate:s, Reporter:s
    153     and File:s.
     157    Request write access to ArrayDesign:s, read access to Plate:s, Reporter:s,
     158    DataFileType:s, Platform:s and File:s.
    154159  */
    155160  public Collection<Permissions> getPermissions()
     
    161166      permissions.add(new Permissions(Item.REPORTER, null, EnumSet.of(Permission.READ)));
    162167      permissions.add(new Permissions(Item.FILE, null, EnumSet.of(Permission.READ)));
     168      permissions.add(new Permissions(Item.PLATFORM, null, EnumSet.of(Permission.READ)));
     169      permissions.add(new Permissions(Item.DATAFILETYPE, null, EnumSet.of(Permission.READ)));
    163170    }
    164171    return permissions;
     
    188195    {
    189196      ArrayDesign ad = (ArrayDesign)item;
    190       if (ad.isAffyChip())
    191       {
    192         message = "Affy array designs are not supported";
    193       }
    194       else if (ad.hasFeatures())
     197      if (ad.isFileOnlyPlatform())
     198      {
     199        message = "Array design is using a file-only platform";
     200      }
     201      else if (ad.getNumDbFeatures() > 0)
    195202      {
    196203        throw new PermissionDeniedException("The array design already has features");
     
    301308    arrayDesign = (ArrayDesign)job.getValue("arrayDesign");
    302309    arrayDesign = ArrayDesign.getById(dc, arrayDesign.getId());
    303     if (arrayDesign.hasFeatures())
     310    File reporterMapFile = (File)job.getValue("file");
     311    printMapMember =
     312      FileStoreUtil.setDataFile(dc, arrayDesign, "generic.printmap", reporterMapFile);
     313    if (arrayDesign.getNumDbFeatures() > 0)
    304314    {
    305315      throw new PermissionDeniedException("The array design already has features: " + arrayDesign.getName()+" ["+arrayDesign.getId()+"]");
     
    447457    throws BaseException
    448458  {
     459    if (printMapMember != null) printMapMember.setValid(success, null);
    449460    if (blocks != null) blocks.clear();
    450461    try
     
    503514      List<PluginParameter<?>> parameters = new ArrayList<PluginParameter<?>>();
    504515      parameters.add(arrayDesignParameter);
     516
     517      ArrayDesign design = null;
     518      int currentArrayDesignId = sc.getCurrentContext(Item.ARRAYDESIGN).getId();
     519      List<File> printMapFiles = null;
     520      dc = sc.newDbControl();
     521      try
     522      {
     523        design = ArrayDesign.getById(dc, currentArrayDesignId);
     524        printMapFiles = FileStoreUtil.getGenericDataFiles(dc, design, FileType.PRINT_MAP);
     525      }
     526      catch (Throwable t)
     527      {}
     528      finally
     529      {
     530        if (dc != null) dc.close();
     531      }
     532     
     533      // The print map file to import from - if a file already hase
     534      // been attached to the array design use it as a default choice
     535      PluginParameter<File> fileParameter = new PluginParameter<File>(
     536        "file",
     537        "Print map file",
     538        "The file with printing information to import features from",
     539        new FileParameterType(printMapFiles == null || printMapFiles.isEmpty() ?
     540          null : printMapFiles.get(0), true, 1)
     541      );
    505542      parameters.add(fileParameter);
    506543      parameters.add(getCharsetParameter(null, null, null));
  • branches/filedb/src/plugins/core/net/sf/basedb/plugins/ReporterMapFlatFileImporter.java

    r3679 r3804  
    3232import net.sf.basedb.core.DbControl;
    3333import net.sf.basedb.core.FeatureBatcher;
     34import net.sf.basedb.core.File;
     35import net.sf.basedb.core.FileParameterType;
     36import net.sf.basedb.core.FileSetMember;
     37import net.sf.basedb.core.FileStoreUtil;
    3438import net.sf.basedb.core.FileType;
    3539import net.sf.basedb.core.InvalidUseOfNullException;
     
    173177  private FeatureBatcher batcher;
    174178  private ReporterBatcher reporterBatcher;
     179  private FileSetMember reporterMapMember;
    175180  private ArrayDesign arrayDesign;
    176181  private Map<BlockInfo, ArrayDesignBlock> blocks;
     
    216221  }
    217222  /**
    218     Request write access to ArrayDesign:s, read access to Reporter:s
    219     and File:s.
     223    Request write access to ArrayDesign:s, read access to Reporter:s,
     224    DataFileType:s, Platform:s and File:s.
    220225  */
    221226  public Collection<Permissions> getPermissions()
     
    226231      permissions.add(new Permissions(Item.REPORTER, null, EnumSet.of(Permission.READ)));
    227232      permissions.add(new Permissions(Item.FILE, null, EnumSet.of(Permission.READ)));
     233      permissions.add(new Permissions(Item.PLATFORM, null, EnumSet.of(Permission.READ)));
     234      permissions.add(new Permissions(Item.DATAFILETYPE, null, EnumSet.of(Permission.READ)));
    228235    }
    229236    return permissions;
     
    263270    {
    264271      ArrayDesign ad = (ArrayDesign)item;
    265       if (ad.isAffyChip())
    266       {
    267         message = "Affy array designs are not supported";
    268       }
    269       else if (ad.hasFeatures())
     272      if (ad.isFileOnlyPlatform())
     273      {
     274        message = "Array design is using a file-only platform";
     275      }
     276      else if (ad.getNumDbFeatures() > 0)
    270277      {
    271278        throw new PermissionDeniedException("The array design already has features");
     
    398405    dc = sc.newDbControl();
    399406    arrayDesign = (ArrayDesign)job.getValue("arrayDesign");
    400     dc.reattachItem(arrayDesign);
    401     if (arrayDesign.hasFeatures())
     407    File reporterMapFile = (File)job.getValue("file");
     408    arrayDesign = ArrayDesign.getById(dc, arrayDesign.getId());
     409    reporterMapMember =
     410      FileStoreUtil.setDataFile(dc, arrayDesign, "generic.reportermap", reporterMapFile);
     411    if (arrayDesign.getNumDbFeatures() > 0)
    402412    {
    403413      throw new PermissionDeniedException("The array design already has features. "+arrayDesign.getName()+"["+arrayDesign.getId()+"]");
     
    486496  {
    487497    if (blocks != null) blocks.clear();
     498    if (reporterMapMember != null) reporterMapMember.setValid(success, null);
    488499    try
    489500    {
     
    542553      List<PluginParameter<?>> parameters = new ArrayList<PluginParameter<?>>();
    543554      parameters.add(arrayDesignParameter);
     555
     556      ArrayDesign design = null;
     557      int currentArrayDesignId = sc.getCurrentContext(Item.ARRAYDESIGN).getId();
     558      List<File> reporterMapFiles = null;
     559      dc = sc.newDbControl();
     560      try
     561      {
     562        design = ArrayDesign.getById(dc, currentArrayDesignId);
     563        reporterMapFiles = FileStoreUtil.getGenericDataFiles(dc, design, FileType.REPORTER_MAP);
     564      }
     565      catch (Throwable t)
     566      {}
     567      finally
     568      {
     569        if (dc != null) dc.close();
     570      }
     571     
     572      // The reporter map file to import from - if a file already hase
     573      // been attached to the array design use it as a default choice
     574      PluginParameter<File> fileParameter = new PluginParameter<File>(
     575        "file",
     576        "Reporter map file",
     577        "The file with reporter information to import features from",
     578        new FileParameterType(reporterMapFiles == null || reporterMapFiles.isEmpty() ?
     579          null : reporterMapFiles.get(0), true, 1)
     580      );
    544581      parameters.add(fileParameter);
    545582      parameters.add(getCharsetParameter(null, null, (String)configuration.getValue(CHARSET)));
  • branches/filedb/src/test/TestArrayDesign.java

    r3797 r3804  
    4343import net.sf.basedb.core.ReporterBatcher;
    4444import net.sf.basedb.core.ItemResultList;
    45 import net.sf.basedb.core.SystemItems;
    4645import net.sf.basedb.core.Well;
    4746import net.sf.basedb.core.data.FeatureData;
     
    105104    // Array designs with data in files
    106105    int cdfId = TestFile.test_create("data/test.affymetrix.cdf", false, false);
    107     test_set_file(id3, "affymetrix.cdf", cdfId);
     106    test_set_file(id3, DataFileType.AFFYMETRIX_CDF, cdfId);
    108107    test_list_files(id3, 1);
    109108
     
    119118    TestPlateType.test_delete(plateType);
    120119    TestPlateGeometry.test_delete(plateGeometry);
    121    
     120    TestFile.test_delete(cdfId);
    122121    TestReporter.test_delete();
    123122
     
    604603      dc = TestUtil.getDbControl();
    605604      ArrayDesign ad = ArrayDesign.getById(dc, arrayDesignId);
    606       DataFileType type = DataFileType.getById(dc, SystemItems.getId(fileType));
     605      DataFileType type = DataFileType.getByExternalId(dc, fileType);
    607606      File file = File.getById(dc, fileId);
    608607      ad.getFileSet().setMember(file, type);
     608      ad.getFileSet().validate(dc, true);
    609609      dc.commit();
    610610      write("--Set file OK ("+fileType+")");
  • branches/filedb/www/common/datafiles/list_files.jsp

    r3802 r3804  
    184184          {
    185185            FileSetMember member = entry.getValue();
     186            DataFileType dft = entry.getKey();
    186187            Boolean validFile = null;
    187188            String validationMessage = "";
     
    189190            File file = null;
    190191            boolean readDataFileType = true;
    191             DataFileType dft = null;
    192192            if (member != null)
    193193            {
Note: See TracChangeset for help on using the changeset viewer.