Changeset 3039


Ignore:
Timestamp:
Dec 18, 2006, 9:58:58 AM (15 years ago)
Author:
Nicklas Nordborg
Message:

Added web services for listing projects and experiments

Location:
branches/webservices/src
Files:
4 added
4 edited

Legend:

Unmodified
Added
Removed
  • branches/webservices/src/test/TestWebservices.java

    r3006 r3039  
    2323*/
    2424import net.sf.basedb.core.Config;
     25import net.sf.basedb.ws.client.ExperimentClient;
    2526import net.sf.basedb.ws.client.ProjectClient;
    2627import net.sf.basedb.ws.client.SessionClient;
     28import net.sf.basedb.ws.info.ItemInfo;
    2729
    2830
     
    4749    int projectId = TestProject.test_create(true);
    4850    testSetActiveProject(client, projectId);
     51    testListProjects(client);
     52    int experimentId = testListExperiments(client);
     53    testListRawBioAssays(client, experimentId);
    4954    testLogout(client);
    5055    TestProject.test_delete(projectId);
     
    132137  }
    133138 
    134 
     139  static void testListProjects(SessionClient client)
     140  {
     141    if (client == null) return;
     142    try
     143    {
     144      ProjectClient projectClient = new ProjectClient(client);
     145      ItemInfo[] projects = projectClient.getProjects();
     146      if (projects != null)
     147      {
     148        for (ItemInfo p : projects)
     149        {
     150          write(p.getId() + "\t" + p.getName());
     151        }
     152      }
     153          write("--List projects OK");
     154    }
     155    catch (Throwable t)
     156    {
     157      write("--List projects FAILED");
     158      t.printStackTrace();
     159      ok = false;
     160    }
     161  }
     162
     163  static int testListExperiments(SessionClient client)
     164  {
     165    if (client == null) return 0;
     166    int experimentId = 0;
     167    try
     168    {
     169      ExperimentClient experimentClient = new ExperimentClient(client);
     170      ItemInfo[] experiments = experimentClient.getExperiments();
     171      if (experiments != null)
     172      {
     173        for (ItemInfo p : experiments)
     174        {
     175          if (experimentId == 0) experimentId = p.getId();
     176          write(p.getId() + "\t" + p.getName());
     177        }
     178      }
     179          write("--List experiments OK");
     180    }
     181    catch (Throwable t)
     182    {
     183      write("--List experiments FAILED");
     184      t.printStackTrace();
     185      ok = false;
     186    }
     187    return experimentId;
     188  }
     189
     190  static void testListRawBioAssays(SessionClient client, int experimentId)
     191  {
     192    if (client == null || experimentId == 0) return;
     193    try
     194    {
     195      ExperimentClient experimentClient = new ExperimentClient(client);
     196      ItemInfo[] rawBioAssays = experimentClient.getRawBioAssays(experimentId);
     197      if (rawBioAssays != null)
     198      {
     199        for (ItemInfo p : rawBioAssays)
     200        {
     201          write(p.getId() + "\t" + p.getName());
     202        }
     203      }
     204          write("--List rawbioassays OK");
     205    }
     206    catch (Throwable t)
     207    {
     208      write("--List rawbioassays FAILED");
     209      t.printStackTrace();
     210      ok = false;
     211    }
     212  }
     213
     214 
     215 
    135216}
  • branches/webservices/src/webservices/client/java/net/sf/basedb/ws/client/ProjectClient.java

    r3006 r3039  
    2424package net.sf.basedb.ws.client;
    2525
     26import net.sf.basedb.ws.info.ItemInfo;
     27
    2628import org.apache.axis2.AxisFault;
     29import org.apache.axis2.rpc.client.RPCServiceClient;
    2730
    2831public class ProjectClient
     
    4447  }
    4548 
     49  public ItemInfo[] getProjects()
     50    throws AxisFault
     51  {
     52    RPCServiceClient service = getService();
     53    ItemInfo[] result = invokeBlocking("getProjects", ItemInfo[].class, session.getId());
     54    return result;
     55  }
     56 
    4657}
  • branches/webservices/src/webservices/server/META-INF/services.xml

    r3006 r3039  
    2424    <parameter name="ServiceClass" locked="false">net.sf.basedb.ws.server.ProjectService</parameter>
    2525  </service>
     26  <service name="Experiment" scope="application">
     27    <description>
     28      This service handles experiments
     29    </description>
     30    <messageReceivers>
     31      <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out"
     32        class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
     33      <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only"
     34        class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" />
     35    </messageReceivers>
     36    <parameter name="ServiceClass" locked="false">net.sf.basedb.ws.server.ExperimentService</parameter>
     37  </service>
    2638</serviceGroup>
  • branches/webservices/src/webservices/server/net/sf/basedb/ws/server/ProjectService.java

    r3006 r3039  
    2424package net.sf.basedb.ws.server;
    2525
     26import java.util.LinkedList;
     27import java.util.List;
     28
    2629import net.sf.basedb.core.DbControl;
     30import net.sf.basedb.core.ItemQuery;
    2731import net.sf.basedb.core.Project;
    2832import net.sf.basedb.core.SessionControl;
     33import net.sf.basedb.ws.info.ItemInfo;
    2934
    3035public class ProjectService
     
    5257    sc.setActiveProject(project);   
    5358  }
     59 
     60  public ItemInfo[] getProjects(String ID)
     61  {
     62    SessionControl sc = getSessionControl(ID);
     63    DbControl dc = sc.newDbControl();
     64    List<ItemInfo> projects = new LinkedList<ItemInfo>();
     65    try
     66    {
     67      ItemQuery<Project> query = Project.getQuery();
     68      for (Project project : query.list(dc))
     69      {
     70        projects.add(new ItemInfo(project));
     71      }
     72    }
     73    finally
     74    {
     75      if (dc != null) dc.close();
     76    }
     77    ItemInfo[] ii = new ItemInfo[projects.size()];
     78    return projects.toArray(ii);
     79  }
    5480}
Note: See TracChangeset for help on using the changeset viewer.