Changeset 5718


Ignore:
Timestamp:
Sep 6, 2011, 12:44:53 PM (10 years ago)
Author:
Nicklas Nordborg
Message:

References #1604: Support for multiple files of the same type in a FileSet?

Updated Web Service API to handle multiple files of the same type.

Location:
trunk
Files:
4 added
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/build.xml

    r5706 r5718  
    10121012    >
    10131013    <mkdir dir="${webservices.wsdlpath}" />
     1014    <webservices.wsdl serviceClassName="AnnotationTypeService"/>
    10141015    <webservices.wsdl serviceClassName="ArrayDesignService"/>
    10151016    <webservices.wsdl serviceClassName="BioAssaySetService"/>
    10161017    <webservices.wsdl serviceClassName="ExperimentService"/>
     1018    <webservices.wsdl serviceClassName="FileService"/>
    10171019    <webservices.wsdl serviceClassName="ProjectService"/>
    10181020    <webservices.wsdl serviceClassName="RawBioAssayService"/>
     1021    <webservices.wsdl serviceClassName="ReporterService"/>
    10191022    <webservices.wsdl serviceClassName="SessionService"/>
    1020     <webservices.wsdl serviceClassName="ReporterService"/>
    1021     <webservices.wsdl serviceClassName="AnnotationTypeService"/>
    10221023  </target>
    10231024 
  • trunk/src/core/net/sf/basedb/core/File.java

    r5652 r5718  
    3030import net.sf.basedb.core.data.ItemSubtypeData;
    3131import net.sf.basedb.core.data.MimeTypeData;
     32import net.sf.basedb.info.FileInfo;
     33import net.sf.basedb.info.ToTransferable;
    3234import net.sf.basedb.util.EqualsHelper;
    3335import net.sf.basedb.util.FileUtil;
     
    7981public class File
    8082  extends CommonItem<FileData>
    81   implements Transactional, DiskConsumable, Subtypable
     83  implements Transactional, DiskConsumable, Subtypable, ToTransferable<FileInfo>
    8284{
    8385  /**
     
    700702    if (isWriteProtected()) denied |= Permission.deny(Permission.DELETE);
    701703    super.initPermissions(granted, denied);
     704  }
     705  /**
     706    @since 3.0
     707  */
     708  @Override
     709  public FileInfo toTransferable(FileInfo info)
     710  {
     711    super.toTransferable(info);
     712    info.setSize(this.getSize());
     713    info.setMimeType(this.getMimeType());
     714    info.setMd5(this.getMd5());
     715    info.setCharacterSet(this.getCharacterSet());
     716    info.setPath(this.getPath().toString());
     717    return info;
    702718  }
    703719  // -------------------------------------------
  • trunk/src/core/net/sf/basedb/core/FileSet.java

    r5714 r5718  
    581581      )
    582582    );
     583    query.setDistinct(true);
    583584    return query;
    584585  }
  • trunk/src/core/net/sf/basedb/core/FileSetMember.java

    r5713 r5718  
    2626import net.sf.basedb.core.query.Hql;
    2727import net.sf.basedb.core.query.Restrictions;
     28import net.sf.basedb.info.DataFileTypeInfo;
     29import net.sf.basedb.info.FileInfo;
     30import net.sf.basedb.info.FileSetMemberInfo;
     31import net.sf.basedb.info.ToTransferable;
    2832
    2933/**
     
    3640public class FileSetMember
    3741  extends BasicItem<FileSetMemberData>
     42  implements ToTransferable<FileSetMemberInfo>
    3843{
    3944 
     
    156161    return PluginPermission.NO_PLUGIN;
    157162  }
     163  /**
     164    @since 3.0
     165  */
     166  public FileSetMemberInfo toTransferable(FileSetMemberInfo info)
     167  {
     168    super.toTransferable(info);
     169    info.setDataFileTypeInfo(this.getDataFileType().toTransferable(new DataFileTypeInfo()));
     170    info.setFileInfo(this.getFile().toTransferable(new FileInfo()));
     171    info.setValid(this.isValid());
     172    info.setErrorMessage(this.getErrorMessage());
     173    return info;
     174  }
    158175  // -------------------------------------------
    159176 
  • trunk/src/test/TestWebservices.java

    r5657 r5718  
    3434import net.sf.basedb.info.ExperimentInfo;
    3535import net.sf.basedb.info.ExtendedPropertyInfo;
     36import net.sf.basedb.info.FileInfo;
     37import net.sf.basedb.info.FileSetMemberInfo;
    3638import net.sf.basedb.info.ProjectInfo;
    3739import net.sf.basedb.info.QueryOptions;
     
    4446import net.sf.basedb.ws.client.BioAssaySetClient;
    4547import net.sf.basedb.ws.client.ExperimentClient;
     48import net.sf.basedb.ws.client.FileClient;
    4649import net.sf.basedb.ws.client.ProjectClient;
    4750import net.sf.basedb.ws.client.RawBioAssayClient;
     
    5255import java.io.File;
    5356import java.io.FileOutputStream;
     57import java.io.IOException;
    5458import java.io.InputStream;
    5559import java.io.OutputStream;
     
    179183    BioAssaySetClient basClient = new BioAssaySetClient(client);
    180184    ExperimentClient experimentClient = new ExperimentClient(client);
     185    FileClient fileClient = new FileClient(client);
    181186   
    182187    int bioAssaySetId = 0;
     
    201206    try
    202207    {
    203       DataFileTypeInfo[] dataFiles = basClient.getDataFileTypes(bioAssaySetId, null);
    204       if (dataFiles == null)
     208      FileSetMemberInfo[] members = basClient.getDataFiles(bioAssaySetId, null);
     209      if (members == null || members.length == 0)
    205210      {
    206211        throw new Exception("Cant find any data files on bioassay set with id = " + bioAssaySetId);
    207212      }
    208213     
    209       for (DataFileTypeInfo info : dataFiles)
    210       {
    211         File receivedFile = new File(info.getExternalId());
     214      for (FileSetMemberInfo info : members)
     215      {
     216        DataFileTypeInfo fileType = info.getDataFileTypeInfo();
     217        FileInfo file = info.getFileInfo();
     218        long expectedSize = file.getSize();
     219        File receivedFile = new File(file.getName());
    212220        OutputStream out = new FileOutputStream(receivedFile);
    213         write("--Downloading file from BioAssaySet: " + info.getExternalId());
    214         InputStream in = basClient.downloadDataFile(bioAssaySetId, info.getExternalId());
     221        write("--Downloading file from BioAssaySet: " + fileType.getExternalId());
     222        InputStream in = fileClient.download(file.getId());
    215223        if (in == null)
    216224        {
     
    220228        in.close();
    221229        out.close();
     230        if (receivedFile.length() != expectedSize)
     231        {
     232          throw new IOException("Download failed. Got " +
     233              receivedFile.length() + " bytes, expected " + expectedSize);
     234        }
    222235        write("--Download OK; size=" + receivedFile.length() + " bytes");
    223236        receivedFile.delete();
     
    248261    if (client == null || rawBioAssayId == 0) return;
    249262    ArrayDesignClient arrayDesignClient = new ArrayDesignClient(client);
    250     RawBioAssayClient rawClient = new RawBioAssayClient(client);   
     263    RawBioAssayClient rawClient = new RawBioAssayClient(client); 
     264    FileClient fileClient = new FileClient(client);
    251265    ArrayDesignInfo designInfo = null;
    252266   
     
    268282      int arrayDesignId = designInfo.getId();
    269283      boolean hasDownloadableData = arrayDesignClient.hasDownloadableData(arrayDesignId);
    270       DataFileTypeInfo[] fileTypes = arrayDesignClient.getDataFileTypes(arrayDesignId, new QueryOptions());
     284      FileSetMemberInfo[] members = arrayDesignClient.getDataFiles(arrayDesignId, new QueryOptions());
    271285       
    272       if (hasDownloadableData && fileTypes.length > 0)
    273       {
    274         write("--Downloading " + fileTypes[0].getName() + " for array design '" + designInfo.getName() + "'");
    275         File receivedFile = new File(fileTypes[0].getName());
     286      if (hasDownloadableData && members.length > 0)
     287      {
     288        DataFileTypeInfo fileType = members[0].getDataFileTypeInfo();
     289        FileInfo file = members[0].getFileInfo();
     290        long expectedSize = file.getSize();
     291        write("--Downloading " + fileType.getName() + " for array design '" + designInfo.getName() + "': " + file.getName());
     292        File receivedFile = new File(file.getName());
    276293        OutputStream out = new FileOutputStream(receivedFile);
    277         InputStream in = arrayDesignClient.downloadArrayDesignByType(arrayDesignId, fileTypes[0].getExternalId());
     294        InputStream in = fileClient.download(file.getId());
    278295        if (in == null)
    279296        {
     
    283300        in.close();
    284301        out.close();
     302        if (receivedFile.length() != expectedSize)
     303        {
     304          throw new IOException("Download failed. Got " +
     305              receivedFile.length() + " bytes, expected " + expectedSize);
     306        }
    285307        write("--Download OK; size=" + receivedFile.length() + " bytes");
    286308        receivedFile.delete();
     
    316338    ExperimentClient experimentClient = new ExperimentClient(client);
    317339    RawBioAssayClient rawClient = new RawBioAssayClient(client);
     340    FileClient fileClient = new FileClient(client);
    318341    try
    319342    {
     
    343366     
    344367      Boolean hasDownloadableData = rawClient.hasDownloadableData(rawBioAssayId);
    345       DataFileTypeInfo[] fileTypes = rawClient.getDataFileTypes(rawBioAssayId, null);
    346      
    347       if (hasDownloadableData && fileTypes.length > 0)
    348       {
    349         write("--Downloading " + fileTypes[0].getName() + " for RawBioAssay '" + raw.getName() + "'");
    350         File receivedFile = new File(fileTypes[0].getName());
     368      FileSetMemberInfo[] members = rawClient.getDataFiles(rawBioAssayId, null);
     369     
     370      if (hasDownloadableData && members.length > 0)
     371      {
     372        DataFileTypeInfo fileType = members[0].getDataFileTypeInfo();
     373        FileInfo file = members[0].getFileInfo();
     374        long expectedSize = file.getSize();
     375        write("--Downloading " + fileType.getName() + " for RawBioAssay '" + raw.getName() + "': " + file.getName());
     376        File receivedFile = new File(file.getName());
    351377        OutputStream out = new FileOutputStream(receivedFile);
    352         InputStream in = rawClient.downloadRawDataByType(rawBioAssayId, fileTypes[0].getExternalId());
     378        InputStream in = fileClient.download(file.getId());
    353379        if (in == null)
    354380        {
     
    360386          in.close();
    361387          out.close();
     388          if (receivedFile.length() != expectedSize)
     389          {
     390            throw new IOException("Download failed. Got " +
     391                receivedFile.length() + " bytes, expected " + expectedSize);
     392          }
    362393          write("--Download OK; size=" + receivedFile.length() + " bytes");
    363394          receivedFile.delete();
  • trunk/src/webservices/client/java/net/sf/basedb/ws/client/ArrayDesignClient.java

    r4513 r5718  
    2424import net.sf.basedb.info.ArrayDesignInfo;
    2525import net.sf.basedb.info.DataFileTypeInfo;
     26import net.sf.basedb.info.FileSetMemberInfo;
    2627import net.sf.basedb.info.QueryOptions;
    2728
     
    9293      @throws IOException If writing to the file fails.
    9394  */
    94   public InputStream downloadArrayDesignByType(int arrayDesignId, String dataFileType)
     95  public InputStream xdownloadArrayDesignByType(int arrayDesignId, String dataFileType)
    9596    throws IOException
    9697  {
     
    129130 
    130131  /**
     132    Returns information about data files that are used storing
     133    feature information for an array design.
     134      @param arrayDesignId Id of the array design to get the information about.
     135      @param qOpt Restrictions and includes to put on the query when getting the information.
     136      @return An array of FileSetMemberInfo, one for each data file used in the array design.
     137      @throws AxisFault If communication with webservice fails.
     138      @since 3.0
     139  */
     140  public FileSetMemberInfo[] getDataFiles(int arrayDesignId, QueryOptions qOpt)
     141    throws AxisFault
     142  {
     143    return invokeBlocking
     144        (
     145          "getDataFiles",
     146          FileSetMemberInfo[].class,
     147          session.getId(),
     148          arrayDesignId,
     149          qOpt
     150        );
     151  }
     152
     153  /**
    131154    Gets if data in an array design can be downloaded as a file or not.
    132155      @param arrayDesignId Id of the array design to check
  • trunk/src/webservices/client/java/net/sf/basedb/ws/client/BioAssaySetClient.java

    r5590 r5718  
    2626
    2727import net.sf.basedb.info.DataFileTypeInfo;
     28import net.sf.basedb.info.FileSetMemberInfo;
    2829import net.sf.basedb.info.QueryOptions;
    2930
     
    9798
    9899  /**
     100    Returns information about data files that are used storing
     101    data for a bioassay set
     102      @param bioAssaySetId Id of the bioassay set to get the information about.
     103      @param qOpt Restrictions and includes to put on the query when getting the information.
     104      @return An array of FileSetMemberInfo, one for each data file used in the bioassay set.
     105      @throws AxisFault If communication with webservice fails.
     106      @since 3.0
     107  */
     108  public FileSetMemberInfo[] getDataFiles(int bioAssaySetId, QueryOptions qOpt)
     109    throws AxisFault
     110  {
     111    return invokeBlocking
     112        (
     113          "getDataFiles",
     114          FileSetMemberInfo[].class,
     115          session.getId(),
     116          bioAssaySetId,
     117          qOpt
     118        );
     119  }
     120
     121 
     122  /**
    99123    Gets spot data as a file for a bioassay set if it is stored in a file
    100124    in BASE.
     
    107131      @since 2.12
    108132  */
    109   public InputStream downloadDataFile(int bioAssaySetId, String dataFileType)
     133  public InputStream xdownloadDataFile(int bioAssaySetId, String dataFileType)
    110134    throws AxisFault, IOException
    111135  {
  • trunk/src/webservices/client/java/net/sf/basedb/ws/client/RawBioAssayClient.java

    r4513 r5718  
    2525import net.sf.basedb.info.ArrayDesignInfo;
    2626import net.sf.basedb.info.DataFileTypeInfo;
     27import net.sf.basedb.info.FileSetMemberInfo;
    2728import net.sf.basedb.info.QueryOptions;
    2829import net.sf.basedb.info.RawBioAssayInfo;
     
    170171 
    171172  /**
     173    Returns information about data files that are used storing
     174    raw data for a raw bioassay.
     175      @param rawBioAssayId Id of the raw bioassay to get the information about.
     176      @param qOpt Restrictions and includes to put on the query when getting the information.
     177      @return An array of FileSetMemberInfo, one for each data file used in the raw bioassay.
     178      @throws AxisFault If communication with webservice fails.
     179      @since 3.0
     180  */
     181  public FileSetMemberInfo[] getDataFiles(int rawBioAssayId, QueryOptions qOpt)
     182    throws AxisFault
     183  {
     184    return invokeBlocking
     185        (
     186          "getDataFiles",
     187          FileSetMemberInfo[].class,
     188          session.getId(),
     189          rawBioAssayId,
     190          qOpt
     191        );
     192  }
     193 
     194 
     195  /**
    172196    Get annotation values for one or more annotation types.
    173197    @param rawBioAssayId Id of the raw bioassay to load the annotations from
  • trunk/src/webservices/server/META-INF/services.xml

    r3978 r5718  
    9696    <parameter name="ServiceClass" locked="false">net.sf.basedb.ws.server.AnnotationTypeService</parameter>
    9797  </service>
     98  <service name="File" scope="application">
     99    <description>
     100      This service handles files
     101    </description>
     102    <messageReceivers>
     103      <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out"
     104        class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
     105      <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only"
     106        class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" />
     107    </messageReceivers>
     108    <parameter name="ServiceClass" locked="false">net.sf.basedb.ws.server.FileService</parameter>
     109  </service>
    98110</serviceGroup>
  • trunk/src/webservices/server/net/sf/basedb/ws/server/ArrayDesignService.java

    r4513 r5718  
    3333import net.sf.basedb.info.ArrayDesignInfo;
    3434import net.sf.basedb.info.DataFileTypeInfo;
     35import net.sf.basedb.info.FileSetMemberInfo;
    3536import net.sf.basedb.info.QueryOptions;
    3637
     
    101102  /**
    102103    Returns array design file of a certain type, attached to an OMElement.
     104    This method assumes that only a single file of the given type exists. If there
     105    are two or more files, then it is not specified which one that is returned.
     106    Use {@link #getDataFiles(String, int, QueryOptions)} and
     107    {@link FileService} to handle the multi-file case.
     108   
    103109      @param ID Used to identify an active session with.
    104110      @param arrayDesignId Id of the array design the file is associated with.
     
    189195 
    190196  /**
     197    Returns information objects for each data file that is associated with
     198    an Array design.
     199      @param ID Id of the active session.
     200      @param arrayDesignId Id of the array design it concerns
     201    @param qOpt Restrictions and includes to put on the query
     202      @return An array with FileSetMemberInfo
     203      @since 3.0
     204  */
     205  public FileSetMemberInfo[] getDataFiles(String ID, int arrayDesignId, QueryOptions qOpt)
     206  {
     207    SessionControl sc = getSessionControl(ID);
     208    DbControl dc = sc.newDbControl();
     209    try
     210    {
     211      ArrayDesign design = ArrayDesign.getById(dc, arrayDesignId);
     212      return util.getDataFiles(dc, design, qOpt);
     213    }
     214    finally
     215    {
     216      if (dc != null) dc.close();
     217    }
     218  }
     219
     220 
     221  /**
    191222    Get the annotation values for one or more annotation types.
    192223    @param ID Id of the active session.
  • trunk/src/webservices/server/net/sf/basedb/ws/server/BioAssaySetService.java

    r5590 r5718  
    3131import net.sf.basedb.info.AnnotationInfo;
    3232import net.sf.basedb.info.DataFileTypeInfo;
     33import net.sf.basedb.info.FileSetMemberInfo;
    3334import net.sf.basedb.info.QueryOptions;
    3435
     
    5657  /**
    5758    Returns a data file of a certain type attached to an OMElement.
     59    This method assumes that only a single file of the given type exists. If there
     60    are two or more files, then it is not specified which one that is returned.
     61    Use {@link #getDataFiles(String, int, QueryOptions)} and
     62    {@link FileService} to handle the multi-file case.
     63
    5864      @param ID Used to identify an active session with.
    5965      @param bioAssaySetId Id of the bioassay set the file belongs to.
     
    144150  }
    145151
     152  /**
     153    Returns information objects for each data file that is associated with
     154    a bioassay set.
     155      @param ID Id of the active session.
     156      @param bioAssaySetId Id of the bioassay set it concerns
     157    @param qOpt Restrictions and includes to put on the query
     158      @return An array with FileSetMemberInfo
     159      @since 3.0
     160  */
     161  public FileSetMemberInfo[] getDataFiles(String ID, int bioAssaySetId, QueryOptions qOpt)
     162  {
     163    SessionControl sc = getSessionControl(ID);
     164    DbControl dc = sc.newDbControl();
     165    try
     166    {
     167      BioAssaySet bas = BioAssaySet.getById(dc, bioAssaySetId);
     168      return util.getDataFiles(dc, bas, qOpt);
     169    }
     170    finally
     171    {
     172      if (dc != null) dc.close();
     173    }
     174  }
     175
    146176 
    147177  /**
  • trunk/src/webservices/server/net/sf/basedb/ws/server/RawBioAssayService.java

    r4513 r5718  
    3333import net.sf.basedb.info.ArrayDesignInfo;
    3434import net.sf.basedb.info.DataFileTypeInfo;
     35import net.sf.basedb.info.FileSetMemberInfo;
    3536import net.sf.basedb.info.QueryOptions;
    3637import net.sf.basedb.info.RawBioAssayInfo;
     
    122123 
    123124  /**
    124     Returns a rawdata file of a certain type attached to an OMElement.
     125    Returns a rawdata file of a certain type attached to an OMElement. This
     126    method assumes that only a single file of the given type exists. If there
     127    are two or more files, then it is not specified which one that is returned.
     128    Use {@link #getDataFiles(String, int, QueryOptions)} and
     129    {@link FileService} to handle the multi-file case.
     130   
    125131      @param ID Used to identify an active session with.
    126132      @param rawBioAssayId Id of the rawbio assay the file belongs to.
     
    129135        or NULL if no file was found.
    130136      @see DataFileType
     137      @see #getDataFiles(String, int, QueryOptions)
    131138  */
    132139  public OMElement downloadRawDataByType(String ID,
     
    211218 
    212219  /**
     220    Returns information objects for each data file that is associated with
     221    a RawBioAssay.
     222      @param ID Id of the active session.
     223      @param rawBioAssayId Id of the rawbioassay it concerns
     224    @param qOpt Restrictions and includes to put on the query
     225      @return An array with FileSetMemberInfo
     226      @since 3.0
     227  */
     228  public FileSetMemberInfo[] getDataFiles(String ID, int rawBioAssayId, QueryOptions qOpt)
     229  {
     230    SessionControl sc = getSessionControl(ID);
     231    DbControl dc = sc.newDbControl();
     232    try
     233    {
     234      RawBioAssay rawBioAssay = RawBioAssay.getById(dc, rawBioAssayId);
     235      return util.getDataFiles(dc, rawBioAssay, qOpt);
     236    }
     237    finally
     238    {
     239      if (dc != null) dc.close();
     240    }
     241  }
     242
     243 
     244  /**
    213245    Get the annotation values for one or more annotation types.
    214246    @param ID Id of the active session.
  • trunk/src/webservices/server/net/sf/basedb/ws/server/ServicesUtil.java

    r5319 r5718  
    2828import net.sf.basedb.core.BasicItem;
    2929import net.sf.basedb.core.DbControl;
     30import net.sf.basedb.core.FileSetMember;
     31import net.sf.basedb.core.FileStoreEnabled;
    3032import net.sf.basedb.core.Include;
    3133import net.sf.basedb.core.ItemQuery;
     
    3335import net.sf.basedb.core.query.Hql;
    3436import net.sf.basedb.info.AnnotationInfo;
     37import net.sf.basedb.info.FileSetMemberInfo;
    3538import net.sf.basedb.info.QueryOptions;
    3639import net.sf.basedb.info.QueryParameter;
     
    167170    return result;
    168171  }
     172 
     173  /**
     174    Returns information objects for each data file that is associated with
     175    a {@link FileStoreEnabled} item.
     176      @param item The item with files
     177    @param qOpt Restrictions and includes to put on the query
     178      @return An array with FileSetMemberInfo
     179      @since 3.0
     180  */
     181  public FileSetMemberInfo[] getDataFiles(DbControl dc, FileStoreEnabled item, QueryOptions qOpt)
     182  {
     183    FileSetMemberInfo[] members = null;
     184    if (item.hasFileSet())
     185    {     
     186      ItemQuery<FileSetMember> query = item.getFileSet().getMembers();
     187      query = getConfiguredItemQuery(query, qOpt);
     188      members = listToInfo(query.list(dc), FileSetMemberInfo.class);
     189    }
     190    else
     191    {
     192      members = new FileSetMemberInfo[0];
     193    }
     194    return members;
     195  }
     196
    169197}
Note: See TracChangeset for help on using the changeset viewer.