Changeset 3876
- Timestamp:
- Oct 24, 2007, 4:58:42 PM (15 years ago)
- Location:
- trunk/src
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/test/TestWebservices.java
r3874 r3876 22 22 Boston, MA 02111-1307, USA. 23 23 */ 24 import net.sf.basedb.core.BioAssaySet; 24 25 import net.sf.basedb.core.Config; 25 26 import net.sf.basedb.core.DataFileType; 27 import net.sf.basedb.core.DbControl; 28 import net.sf.basedb.core.Formula; 29 import net.sf.basedb.core.ItemQuery; 26 30 import net.sf.basedb.core.Platform; 31 import net.sf.basedb.core.query.Expressions; 32 import net.sf.basedb.core.query.Hql; 33 import net.sf.basedb.core.query.Restrictions; 27 34 import net.sf.basedb.ws.client.ArrayDesignClient; 28 35 import net.sf.basedb.ws.client.BioAssaySetClient; … … 40 47 41 48 import java.io.File; 49 import java.util.ArrayList; 42 50 43 51 /** … … 48 56 { 49 57 static boolean ok = true; 58 59 /** 60 @param args 61 */ 50 62 public static void main(String[] args) 51 63 { … … 78 90 TestExperiment.test_add_rawbioassay(experimentId1, rawBioAssayId1); 79 91 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); 81 93 82 94 //Experiment with rawdata and array design stored in files. … … 96 108 //Tests 97 109 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 } 109 120 110 121 //Standard test:Delete/cleanup … … 150 161 BioAssaySetClient basClient = new BioAssaySetClient(client); 151 162 ExperimentClient experimentClient = new ExperimentClient(client); 152 163 DbControl dc = null; 153 164 try 154 165 { … … 177 188 else 178 189 { 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()]; 182 214 boolean mergeReporters = false; 215 183 216 for (String format : exportFormats) 184 217 { 185 System.out.print("BioAssaySet being downloaded in format " + format + "..."); 218 File receivedFile = null; 219 System.out.print("--Download BioAssaySet in file format " + format + "..."); 186 220 receivedFile = basClient.downloadBioAssaySet( 187 bioAssaySetId, format, format, rep orterFields, spotFields, mergeReporters);221 bioAssaySetId, format, format, rep.toArray(reporterFields), spot.toArray(spotFields), mergeReporters); 188 222 if (receivedFile == null) 189 223 { … … 205 239 t.printStackTrace(); 206 240 ok = false; 241 } 242 finally 243 { 244 if (dc != null)dc.close(); 207 245 } 208 246 } … … 220 258 @param arrayDesignId Id of the ArrayDesign to test with 221 259 */ 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; 225 263 ArrayDesignClient arrayDesignClient = new ArrayDesignClient(client); 226 RawBioAssayClient rawClient = new RawBioAssayClient(client); 227 264 RawBioAssayClient rawClient = new RawBioAssayClient(client); 228 265 ArrayDesignInfo designInfo = null; 229 266 230 267 try 231 268 { 232 designInfo = rawClient.getArrayDesign(rawBioAssayId); 269 designInfo = rawClient.getArrayDesign(rawBioAssayId); 233 270 } 234 271 catch (Throwable t) … … 240 277 if (designInfo != null) 241 278 { 242 int arrayDesignId = designInfo.getId();243 279 try 244 280 { … … 246 282 DataFileTypeInfo[] fileTypes = arrayDesignClient.getDataFileTypes(arrayDesignId, new QueryOptions()); 247 283 248 249 284 if (hasDownloadableData && fileTypes.length > 0) 250 285 { 286 System.out.print("--Download of array design file...."); 251 287 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"); 253 294 } 254 295 else 255 296 { 256 297 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"); 258 299 } 259 260 write ("--Test of ArrayDesignClient OK");261 300 } 262 301 catch (Throwable t) … … 267 306 } 268 307 } 308 else write ("--No info about the Raw BioAssay was received"); 309 write ("--Test of ArrayDesignClient OK"); 269 310 } 270 311 … … 320 361 if (hasDownloadableData && fileTypes.length > 0) 321 362 { 322 System.out.print("--Download ingraw data file for RawBioAssay....");363 System.out.print("--Download of raw data file for RawBioAssay...."); 323 364 File receivedFile = rawClient.downloadRawDataByType(rawBioAssayId, fileTypes[0], fileTypes[0].getName()); 324 365 if (receivedFile != null) … … 329 370 else write("FAILED"); 330 371 } 372 write ("--Test of RawBioAssayClient OK"); 331 373 } 332 374 catch(Throwable t) … … 341 383 static void test_ProjectClient(SessionClient client, int projectId) 342 384 { 343 if (client == null ) return;385 if (client == null || projectId == 0) return; 344 386 345 387 ProjectClient projectClient = new ProjectClient(client); … … 347 389 { 348 390 //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)) 351 395 { 352 write("--" + infos.length + " projects were received.");396 throw new Exception("No project was received"); 353 397 } 354 398 355 399 //Tests ProjectClient.setActive(int projectId) 356 projectClient.setActive(projectId); 357 write("--Active project has been changed."); 400 projectClient.setActive(projectId); 358 401 write("--Test of ProjectClient OK"); 359 402 } … … 385 428 { 386 429 write("--Create/login session FAILED"); 387 t.printStackTrace();388 ok = false;430 write("--Skipping webservices test."); 431 return null; 389 432 } 390 433 try 391 434 { 392 435 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"); 394 437 } 395 438 catch(Throwable t) -
trunk/src/webservices/client/java/net/sf/basedb/ws/client/AbstractRPCClient.java
r3861 r3876 39 39 import org.apache.axis2.rpc.client.RPCServiceClient; 40 40 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 */ 41 48 public abstract class AbstractRPCClient 42 49 { … … 48 55 } 49 56 57 @SuppressWarnings("unchecked") 50 58 protected Object[] invokeBlocking(String operation, Object[] args, Class[] returnTypes) 51 59 throws AxisFault … … 73 81 OMElement response = getService().invokeBlocking(getOperation(operation), args); 74 82 OMElement fileElement = response.getFirstElement(); 75 OMElement dataElement = fileElement.getFirstElement(); 83 OMElement dataElement = fileElement.getFirstElement(); 84 if (dataElement == null) return null; 76 85 OMText node = (OMText) dataElement.getFirstOMChild(); 77 86 node.setBinary(true); -
trunk/src/webservices/client/java/net/sf/basedb/ws/client/BioAssaySetClient.java
r3874 r3876 33 33 34 34 /** 35 35 Web service client for BioAssaySetService in BASE. 36 {@link net.sf.basedb.ws.server.BioAssaySetService} 36 37 @author Martin 37 38 @version 2.5 … … 42 43 private final SessionClient session; 43 44 45 /** 46 Creates new BioAssayClient for a session. 47 @param session Active session. 48 */ 44 49 public BioAssaySetClient(SessionClient session) 45 50 { … … 48 53 } 49 54 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 */ 50 61 public String[] getExportFormats() 51 62 throws AxisFault 52 63 { 53 RPCServiceClient service = getService();54 64 String[] formats = invokeBlocking("getExportFormats", String[].class, session.getId()); 55 65 return formats; 56 66 } 57 67 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) 59 83 throws AxisFault, IOException 60 84 { … … 74 98 spotFields, 75 99 mergeReporters 76 ); 77 100 ); 78 101 return receivedFile; 79 102 } -
trunk/src/webservices/client/java/net/sf/basedb/ws/client/ExperimentClient.java
r3874 r3876 30 30 31 31 import org.apache.axis2.AxisFault; 32 import org.apache.axis2.rpc.client.RPCServiceClient;33 32 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 */ 34 39 public class ExperimentClient 35 40 extends AbstractRPCClient 36 { 37 41 { 38 42 private final SessionClient session; 39 43 44 /** 45 Creates a new client in active session 46 @param session The active session 47 */ 40 48 public ExperimentClient(SessionClient session) 41 49 { … … 44 52 } 45 53 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 */ 46 60 public ExperimentInfo[] getExperiments(QueryOptions qOpt) 47 61 throws AxisFault 48 62 { 49 RPCServiceClient service = getService();50 63 ExperimentInfo[] result = invokeBlocking("getExperiments", ExperimentInfo[].class, session.getId(), qOpt); 51 64 return result; 52 65 } 53 66 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 */ 54 74 public RawBioAssayInfo[] getRawBioAssays(int experimentId, QueryOptions qOpt) 55 75 throws AxisFault 56 76 { 57 RPCServiceClient service = getService();58 77 RawBioAssayInfo[] result = invokeBlocking("getRawBioAssays", RawBioAssayInfo[].class, session.getId(), experimentId, qOpt); 59 78 return result; 60 79 } 61 80 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 */ 62 88 public BioAssaySetInfo[] getBioAssaySets(int experimentId, QueryOptions qOpt) 63 89 throws AxisFault 64 90 { 65 RPCServiceClient service = getService();66 91 BioAssaySetInfo[] result = invokeBlocking("getBioAssaySets", BioAssaySetInfo[].class, session.getId(), experimentId, new QueryOptions()); 67 92 return result; 68 } 69 93 } 70 94 } -
trunk/src/webservices/client/java/net/sf/basedb/ws/client/ProjectClient.java
r3861 r3876 28 28 29 29 import org.apache.axis2.AxisFault; 30 import org.apache.axis2.rpc.client.RPCServiceClient;31 30 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 */ 32 37 public class ProjectClient 33 38 extends AbstractRPCClient 34 39 { 35 36 40 private final SessionClient session; 37 41 42 /** 43 Creates new ProjectClient object for an active session client. 44 @param session The active session client 45 */ 38 46 public ProjectClient(SessionClient session) 39 47 { … … 42 50 } 43 51 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 */ 44 57 public void setActive(int projectId) 45 58 throws AxisFault … … 48 61 } 49 62 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 */ 50 69 public ProjectInfo[] getProjects(QueryOptions qOpt) 51 70 throws AxisFault 52 71 { 53 RPCServiceClient service = getService();54 72 ProjectInfo[] result = invokeBlocking("getProjects", ProjectInfo[].class, session.getId(), qOpt); 55 73 return result; -
trunk/src/webservices/client/java/net/sf/basedb/ws/client/RawBioAssayClient.java
r3874 r3876 101 101 filePath, 102 102 session.getId(), 103 rawBioAssayId 103 rawBioAssayId, 104 info 104 105 ); 105 106 return receivedFile; -
trunk/src/webservices/client/java/net/sf/basedb/ws/client/SessionClient.java
r3874 r3876 38 38 private final String ID; 39 39 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 */ 40 47 public SessionClient(String url, String ID, String externalClientId) 41 48 throws AxisFault … … 64 71 } 65 72 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 */ 66 78 public String getChallenge() 67 79 throws AxisFault -
trunk/src/webservices/server/net/sf/basedb/ws/server/ArrayDesignService.java
r3874 r3876 69 69 int arrayDesignId, DataFileTypeInfo typeInfo) 70 70 { 71 if (ID == null || typeInfo == null) return null; 71 72 File arrayDesignFile = null; 72 73 SessionControl sc = getSessionControl(ID); … … 144 145 if (design.hasFileSet()) 145 146 { 146 ItemQuery<DataFileType> query = design.getFileSet().getMemberTypes(); 147 FileSet fileSet = design.getFileSet(); 148 ItemQuery<FileSetMember> query = fileSet.getMembers(); 147 149 if (qOpt != null) util.getConfiguredItemQuery(query, qOpt); 148 for ( DataFileType dft: query.list(dc))150 for (FileSetMember fsm : query.list(dc)) 149 151 { 150 types.add(new DataFileTypeInfo( dft));152 types.add(new DataFileTypeInfo(fsm.getDataFileType())); 151 153 } 152 154 } -
trunk/src/webservices/server/net/sf/basedb/ws/server/RawBioAssayService.java
r3874 r3876 93 93 int rawBioAssayId, DataFileTypeInfo typeInfo) 94 94 { 95 if (ID == null || typeInfo == null) return null; 95 96 File rawDataFile = null; 96 97 SessionControl sc = getSessionControl(ID); … … 167 168 RawBioAssay rawBioAssay = RawBioAssay.getById(dc, rawBioAssayId); 168 169 if (rawBioAssay.hasFileSet()) 169 { 170 ItemQuery< DataFileType> query = rawBioAssay.getFileSet().getMemberTypes();170 { 171 ItemQuery<FileSetMember> query = rawBioAssay.getFileSet().getMembers(); 171 172 if (qOpt != null) util.getConfiguredItemQuery(query, qOpt); 172 for ( DataFileType dft: query.list(dc))173 for (FileSetMember fsm : query.list(dc)) 173 174 { 174 types.add(new DataFileTypeInfo( dft));175 types.add(new DataFileTypeInfo(fsm.getDataFileType())); 175 176 } 176 177 }
Note: See TracChangeset
for help on using the changeset viewer.