Changeset 3876


Ignore:
Timestamp:
Oct 24, 2007, 4:58:42 PM (14 years ago)
Author:
Martin Svensson
Message:

References #492 Tests for webservices completed. Fixed the bugs that were found.

Location:
trunk/src
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/test/TestWebservices.java

    r3874 r3876  
    2222  Boston, MA  02111-1307, USA.
    2323*/
     24import net.sf.basedb.core.BioAssaySet;
    2425import net.sf.basedb.core.Config;
    2526import net.sf.basedb.core.DataFileType;
     27import net.sf.basedb.core.DbControl;
     28import net.sf.basedb.core.Formula;
     29import net.sf.basedb.core.ItemQuery;
    2630import net.sf.basedb.core.Platform;
     31import net.sf.basedb.core.query.Expressions;
     32import net.sf.basedb.core.query.Hql;
     33import net.sf.basedb.core.query.Restrictions;
    2734import net.sf.basedb.ws.client.ArrayDesignClient;
    2835import net.sf.basedb.ws.client.BioAssaySetClient;
     
    4047
    4148import java.io.File;
     49import java.util.ArrayList;
    4250
    4351/**
     
    4856{
    4957  static boolean ok = true;
     58 
     59  /**
     60      @param args
     61  */
    5062  public static void main(String[] args)
    5163  {
     
    7890    TestExperiment.test_add_rawbioassay(experimentId1, rawBioAssayId1);
    7991    TestExperiment.test_add_rawbioassay(experimentId1, rawBioAssayId2);
    80     int rootBioAssaySetId1 = TestExperiment.test_create_root_bioassayset_using_calculator(experimentId1, "mean", rawBioAssayId1, rawBioAssayId2);;
     92    int rootBioAssaySetId1 = TestExperiment.test_create_root_bioassayset_using_calculator(experimentId1, "mean", rawBioAssayId1, rawBioAssayId2);
    8193   
    8294    //Experiment with rawdata and array design stored in files.
     
    96108    //Tests
    97109    SessionClient client = test_SessionClient();
    98    
    99     test_ProjectClient(client, projectId);
    100 //    test_getRawDataInExperiment(client, experimentId1, rawBioAssayId1);
    101 //    test_getRawDataInExperiment(client, experimentId2, rawBioAssayId3);
    102 //   
    103 //    test_getArrayDesign(client, rawBioAssayId1);
    104 //    test_getArrayDesign(client, rawBioAssayId2);
    105 //   
    106 //    test_BioAssaySetClient(client, experimentId1, rootBioAssaySetId1);
    107 //       
    108     test_Logout(client);
     110    if (client != null)
     111    {
     112      test_ProjectClient(client, projectId);
     113      test_getRawDataInExperiment(client, experimentId1, rawBioAssayId1);
     114      test_getRawDataInExperiment(client, experimentId2, rawBioAssayId3);   
     115      test_getArrayDesign(client, rawBioAssayId1, arrayDesignId1);
     116      test_getArrayDesign(client, rawBioAssayId3, arrayDesignId2);   
     117      test_BioAssaySetClient(client, experimentId1, rootBioAssaySetId1);       
     118      test_Logout(client);
     119    }
    109120   
    110121    //Standard test:Delete/cleanup
     
    150161    BioAssaySetClient basClient = new BioAssaySetClient(client);
    151162    ExperimentClient experimentClient = new ExperimentClient(client);
    152        
     163    DbControl dc = null;   
    153164    try
    154165    {
     
    177188      else
    178189      {
    179         File receivedFile = null;
    180         String[] reporterFields = {};
    181         String[] spotFields = {};
     190     
     191        dc = TestUtil.getDbControl();
     192        BioAssaySet bas = BioAssaySet.getById(dc, bioAssaySetId);
     193       
     194        ArrayList<String> rep = new ArrayList<String>();
     195        rep.add("rep.id");
     196        rep.add("rep.name");
     197        rep.add("rep.position");
     198       
     199        ArrayList<String> spot = new ArrayList<String>();
     200        ItemQuery<Formula> ratio = Formula.getQuery(Formula.Type.COLUMN_EXPRESSION, bas.getRawDataType());
     201        ratio.restrict(Restrictions.eq(Hql.property("name"), Expressions.string("Ratio, ch1 / ch2")));
     202        if (ratio.count(dc) < 1)
     203        {
     204          throw new Exception("Cant find formula 'Ratio, ch1 / ch2'");
     205        }
     206        spot.add("intensity1");
     207        spot.add("raw.row");
     208        spot.add("raw.col");
     209        spot.add("raw.flags");
     210        spot.add("frm."+ratio.list(dc).get(0).getId());
     211
     212        String[] reporterFields = new String[rep.size()];
     213        String[] spotFields = new String[spot.size()];
    182214        boolean mergeReporters = false;
     215       
    183216        for (String format : exportFormats)
    184217        {
    185           System.out.print("BioAssaySet being downloaded in format " + format + "...");
     218          File receivedFile = null;
     219          System.out.print("--Download BioAssaySet in file format " + format + "...");
    186220          receivedFile = basClient.downloadBioAssaySet(
    187               bioAssaySetId, format, format, reporterFields, spotFields, mergeReporters);
     221              bioAssaySetId, format, format, rep.toArray(reporterFields), spot.toArray(spotFields), mergeReporters);
    188222          if (receivedFile == null)
    189223          {
     
    205239      t.printStackTrace();
    206240      ok = false;
     241    }
     242    finally
     243    {
     244      if (dc != null)dc.close();
    207245    }
    208246  }
     
    220258      @param arrayDesignId Id of the ArrayDesign to test with
    221259   */
    222   static void test_getArrayDesign(SessionClient client, int rawBioAssayId)
    223   {
    224     if (client == null || rawBioAssayId == 0) return;
     260  static void test_getArrayDesign(SessionClient client, int rawBioAssayId, int arrayDesignId)
     261  {
     262    if (client == null || rawBioAssayId == 0 || arrayDesignId == 0) return;
    225263    ArrayDesignClient arrayDesignClient = new ArrayDesignClient(client);
    226     RawBioAssayClient rawClient = new RawBioAssayClient(client);
    227    
     264    RawBioAssayClient rawClient = new RawBioAssayClient(client);   
    228265    ArrayDesignInfo designInfo = null;
    229266   
    230267    try
    231268    {         
    232       designInfo = rawClient.getArrayDesign(rawBioAssayId);
     269      designInfo = rawClient.getArrayDesign(rawBioAssayId);     
    233270    }
    234271    catch (Throwable t)
     
    240277    if (designInfo != null)
    241278    {
    242       int arrayDesignId = designInfo.getId();
    243279      try
    244280      {
     
    246282        DataFileTypeInfo[] fileTypes = arrayDesignClient.getDataFileTypes(arrayDesignId, new QueryOptions());
    247283       
    248        
    249284        if (hasDownloadableData && fileTypes.length > 0)
    250285        {
     286          System.out.print("--Download of array design file....");
    251287          File receivedFile = arrayDesignClient.downloadArrayDesignByType(arrayDesignId, fileTypes[0], fileTypes[0].getName());
    252           receivedFile.delete();
     288          if (receivedFile != null)
     289          {
     290            receivedFile.delete();
     291            write("OK");
     292          }
     293          else throw new Exception("Download file FAILED");
    253294        }
    254295        else
    255296        {
    256297          File receivedFile = arrayDesignClient.downloadArrayDesignByType(arrayDesignId, null, "nullFile");
    257           if (receivedFile != null) write("--ArrayDesignClient download data FAILED");
     298          if (receivedFile != null) throw new Exception("Received a file though the array design doesn't have any downloadable data");
    258299        }
    259        
    260         write ("--Test of ArrayDesignClient OK");
    261300      }
    262301      catch (Throwable t)
     
    267306      }
    268307    }
     308    else write ("--No info about the Raw BioAssay was received");
     309    write ("--Test of ArrayDesignClient OK");
    269310  }
    270311 
     
    320361      if (hasDownloadableData && fileTypes.length > 0)
    321362      {
    322         System.out.print("--Downloading raw data file for RawBioAssay....");
     363        System.out.print("--Download of raw data file for RawBioAssay....");
    323364        File receivedFile = rawClient.downloadRawDataByType(rawBioAssayId, fileTypes[0], fileTypes[0].getName());
    324365        if (receivedFile != null)
     
    329370        else write("FAILED");
    330371      }
     372      write ("--Test of RawBioAssayClient OK");
    331373    }
    332374    catch(Throwable t)
     
    341383  static void test_ProjectClient(SessionClient client, int projectId)
    342384  {
    343     if (client == null) return;
     385    if (client == null || projectId == 0) return;
    344386   
    345387    ProjectClient projectClient = new ProjectClient(client);
     
    347389    {
    348390      //Tests ProjectClient.getProjects(QueryOptions qOpt)
    349       ProjectInfo[] infos = projectClient.getProjects(new QueryOptions());
    350       if (infos != null && infos.length > 0)
     391      QueryOptions qOpt = new QueryOptions();
     392      qOpt.setRestrictionWithPrefix("$id="+projectId, "$");
     393      ProjectInfo[] infos = projectClient.getProjects(qOpt);
     394      if (!(infos != null && infos.length > 0))
    351395      {       
    352         write("--" + infos.length + " projects were received.");
     396        throw new Exception("No project was received");
    353397      }
    354398     
    355399      //Tests ProjectClient.setActive(int projectId)
    356       projectClient.setActive(projectId);
    357       write("--Active project has been changed.");
     400      projectClient.setActive(projectId);     
    358401      write("--Test of ProjectClient OK");
    359402    }   
     
    385428    {
    386429      write("--Create/login session FAILED");
    387       t.printStackTrace();
    388       ok = false;
     430      write("--Skipping webservices test.");
     431      return null;
    389432    }
    390433    try
    391434    {
    392435      client.refreshSession(client.getId());
    393       write("--Refresh session OK \tSession will timeout after: " + client.getSessionTimeOut() + " minutes");
     436      write("--Refresh session OK \tSession timeout set to: " + client.getSessionTimeOut() + " minutes");
    394437    }
    395438    catch(Throwable t)
  • trunk/src/webservices/client/java/net/sf/basedb/ws/client/AbstractRPCClient.java

    r3861 r3876  
    3939import org.apache.axis2.rpc.client.RPCServiceClient;
    4040
     41/**
     42  Abstract class for RPCServiceClients in web services.
     43  Holds information about the service to use
     44  and gives different ways of   
     45    @author Martin
     46    @version 2.5
     47 */
    4148public abstract class AbstractRPCClient
    4249{
     
    4855  }
    4956 
     57  @SuppressWarnings("unchecked")
    5058  protected Object[] invokeBlocking(String operation, Object[] args, Class[] returnTypes)
    5159    throws AxisFault
     
    7381    OMElement response = getService().invokeBlocking(getOperation(operation), args);
    7482    OMElement fileElement = response.getFirstElement();
    75     OMElement dataElement = fileElement.getFirstElement();   
     83    OMElement dataElement = fileElement.getFirstElement(); 
     84    if (dataElement == null) return null;
    7685    OMText node = (OMText) dataElement.getFirstOMChild();
    7786    node.setBinary(true);
  • trunk/src/webservices/client/java/net/sf/basedb/ws/client/BioAssaySetClient.java

    r3874 r3876  
    3333
    3434/**
    35  
     35  Web service client for BioAssaySetService in BASE.
     36  {@link net.sf.basedb.ws.server.BioAssaySetService}
    3637    @author Martin
    3738    @version 2.5
     
    4243  private final SessionClient session;
    4344 
     45  /**
     46    Creates new BioAssayClient for a session.
     47      @param session Active session.
     48   */
    4449  public BioAssaySetClient(SessionClient session)
    4550  {
     
    4853  }
    4954 
     55  /**
     56    Calls the BioAssaySetService and gets the available formats to export
     57    a BioAssaySet from BASE in.
     58      @return An array with the formats.
     59      @throws AxisFault If communication with the service fails.
     60   */
    5061  public String[] getExportFormats()
    5162    throws AxisFault
    5263  {
    53     RPCServiceClient service = getService();
    5464    String[] formats = invokeBlocking("getExportFormats", String[].class, session.getId());
    5565    return formats;
    5666  }
    5767 
    58   public File downloadBioAssaySet(int bioAssaySetId, String filePath, String format, String[] reporterFields, String[] spotFields, boolean mergeReporters)
     68  /**
     69    Call the service in BioAssaySetService that exports a bioassay set and
     70    then sends it as a file.
     71      @param bioAssaySetId Id of the bioAssay set to export
     72      @param filePath Abstract file path to give to the received file.
     73      @param format Export format to use when exporting the bioassay set
     74      @param reporterFields Reporter fields to include in the export
     75      @param spotFields Spot fields to include in the export
     76      @param mergeReporters If the reporters should be merged or not.
     77      @return A file at the specified path
     78      @throws AxisFault If communication with services fails.
     79      @throws IOException If accessing the file files.
     80   */
     81  public File downloadBioAssaySet(int bioAssaySetId, String filePath, String format,
     82      String[] reporterFields, String[] spotFields, boolean mergeReporters)
    5983    throws AxisFault, IOException
    6084  {
     
    7498        spotFields,
    7599        mergeReporters
    76       ); 
    77    
     100      );     
    78101    return receivedFile;
    79102  }
  • trunk/src/webservices/client/java/net/sf/basedb/ws/client/ExperimentClient.java

    r3874 r3876  
    3030
    3131import org.apache.axis2.AxisFault;
    32 import org.apache.axis2.rpc.client.RPCServiceClient;
    3332
     33/**
     34  Webservice client for Experiment.
     35  Call services in {@link net.sf.basedb.ws.server.ExperimentService}
     36    @author Martin
     37    @version 2.5
     38 */
    3439public class ExperimentClient
    3540  extends AbstractRPCClient
    36 {
    37  
     41{
    3842  private final SessionClient session;
    3943 
     44  /**
     45    Creates a new client in active session
     46      @param session The active session
     47   */
    4048  public ExperimentClient(SessionClient session)
    4149  {
     
    4452  }
    4553 
     54  /**
     55    Gets info about experiments that are available in the logged in session.
     56      @param qOpt Options to put on the query that gets the experiments.
     57      @return An array with info object for each experiment that was found.
     58      @throws AxisFault If communication with web service fails.
     59   */
    4660  public ExperimentInfo[] getExperiments(QueryOptions qOpt)
    4761    throws AxisFault
    4862  {
    49     RPCServiceClient service = getService();
    5063    ExperimentInfo[] result = invokeBlocking("getExperiments", ExperimentInfo[].class, session.getId(), qOpt);
    5164    return result;
    5265  }
    5366 
     67  /**
     68    Gets info about raw bioassays used in an experiment.   
     69      @param experimentId Id of experiment to get raw bioassays from.
     70      @param qOpt Options to put on the query that gets the raw bioassays.
     71      @return An array with info object about each raw bioassay that was found.
     72      @throws AxisFault If communication with web services fails.
     73   */
    5474  public RawBioAssayInfo[] getRawBioAssays(int experimentId, QueryOptions qOpt)
    5575    throws AxisFault
    5676  {
    57     RPCServiceClient service = getService();
    5877    RawBioAssayInfo[] result = invokeBlocking("getRawBioAssays", RawBioAssayInfo[].class, session.getId(), experimentId, qOpt);
    5978    return result;
    6079  }
    6180 
     81  /**
     82    Gets info about bioassay sets in an experiment
     83      @param experimentId Id of the experiment to get the bioassay sets from
     84      @param qOpt Options to put on the query that gets the bioassay sets.
     85      @return An array with info about each bioassay set found by the query.
     86      @throws AxisFault If communication with web services fails.
     87   */
    6288  public BioAssaySetInfo[] getBioAssaySets(int experimentId, QueryOptions qOpt)
    6389    throws AxisFault
    6490  {
    65     RPCServiceClient service = getService();
    6691    BioAssaySetInfo[] result = invokeBlocking("getBioAssaySets", BioAssaySetInfo[].class, session.getId(), experimentId, new QueryOptions());
    6792    return result;
    68   }
    69  
     93  }
    7094}
  • trunk/src/webservices/client/java/net/sf/basedb/ws/client/ProjectClient.java

    r3861 r3876  
    2828
    2929import org.apache.axis2.AxisFault;
    30 import org.apache.axis2.rpc.client.RPCServiceClient;
    3130
     31/**
     32  Web service client for project in BASE.
     33  Calls services in {@link net.sf.basedb.ws.server.ProjectService}
     34    @author Martin
     35    @version 2.5
     36 */
    3237public class ProjectClient
    3338  extends AbstractRPCClient
    3439{
    35  
    3640  private final SessionClient session;
    3741 
     42  /**
     43    Creates new ProjectClient object for an active session client.
     44      @param session The active session client
     45   */
    3846  public ProjectClient(SessionClient session)
    3947  {
     
    4250  }
    4351 
     52  /**
     53    Sets a project to be active.
     54      @param projectId Id of the project that should be put active.
     55      @throws AxisFault If communication with web services fails.
     56   */
    4457  public void setActive(int projectId)
    4558    throws AxisFault
     
    4861  }
    4962 
     63  /**
     64    Gets info about each projects that are available for the active session client.
     65      @param qOpt Options to put on the query that gets the project from database.
     66      @return An array with a info object for each project.
     67      @throws AxisFault If communication with web service fails.
     68   */
    5069  public ProjectInfo[] getProjects(QueryOptions qOpt)
    5170    throws AxisFault
    5271  {   
    53     RPCServiceClient service = getService();
    5472    ProjectInfo[] result = invokeBlocking("getProjects", ProjectInfo[].class, session.getId(), qOpt);
    5573    return result;
  • trunk/src/webservices/client/java/net/sf/basedb/ws/client/RawBioAssayClient.java

    r3874 r3876  
    101101        filePath,
    102102        session.getId(),
    103         rawBioAssayId
     103        rawBioAssayId,
     104        info
    104105      );
    105106    return receivedFile;
  • trunk/src/webservices/client/java/net/sf/basedb/ws/client/SessionClient.java

    r3874 r3876  
    3838  private final String ID;
    3939 
     40  /**
     41    Creates a new SessionClient to a certain URL.
     42      @param url The url where web services are located.
     43      @param ID Session id of a logged in session. A new session will be created if this is NULL.
     44      @param externalClientId External id of the client that is registered in BASE.
     45      @throws AxisFault If communication with the web service fails.
     46   */
    4047  public SessionClient(String url, String ID, String externalClientId)
    4148    throws AxisFault
     
    6471  }
    6572 
     73  /**
     74    Calling the getChallenge method.
     75      @return Gets a random string to use with password encryption.
     76      @throws AxisFault If communication with web service fails.
     77   */
    6678  public String getChallenge()
    6779    throws AxisFault
  • trunk/src/webservices/server/net/sf/basedb/ws/server/ArrayDesignService.java

    r3874 r3876  
    6969        int arrayDesignId, DataFileTypeInfo typeInfo)
    7070  {
     71    if (ID == null || typeInfo == null) return null;
    7172    File arrayDesignFile = null;
    7273    SessionControl sc = getSessionControl(ID);
     
    144145      if (design.hasFileSet())
    145146      {
    146         ItemQuery<DataFileType> query = design.getFileSet().getMemberTypes();
     147        FileSet fileSet = design.getFileSet();
     148        ItemQuery<FileSetMember> query = fileSet.getMembers();       
    147149        if (qOpt != null) util.getConfiguredItemQuery(query, qOpt);
    148         for (DataFileType dft : query.list(dc))
     150        for (FileSetMember fsm : query.list(dc))
    149151        {
    150           types.add(new DataFileTypeInfo(dft));
     152          types.add(new DataFileTypeInfo(fsm.getDataFileType()));
    151153        }
    152154      }
  • trunk/src/webservices/server/net/sf/basedb/ws/server/RawBioAssayService.java

    r3874 r3876  
    9393      int rawBioAssayId, DataFileTypeInfo typeInfo)
    9494  {
     95    if (ID == null || typeInfo == null) return null;
    9596    File rawDataFile = null;
    9697    SessionControl sc = getSessionControl(ID);
     
    167168      RawBioAssay rawBioAssay = RawBioAssay.getById(dc, rawBioAssayId);
    168169      if (rawBioAssay.hasFileSet())
    169       {
    170         ItemQuery<DataFileType> query = rawBioAssay.getFileSet().getMemberTypes();
     170      {     
     171        ItemQuery<FileSetMember> query = rawBioAssay.getFileSet().getMembers();
    171172        if (qOpt != null) util.getConfiguredItemQuery(query, qOpt);
    172         for (DataFileType dft : query.list(dc))
     173        for (FileSetMember fsm : query.list(dc))
    173174        {
    174           types.add(new DataFileTypeInfo(dft));
     175          types.add(new DataFileTypeInfo(fsm.getDataFileType()));
    175176        }
    176177      }
Note: See TracChangeset for help on using the changeset viewer.