Changeset 3984
- Timestamp:
- Nov 20, 2007, 2:02:22 PM (16 years ago)
- Location:
- trunk/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/core/net/sf/basedb/core/RawBioAssay.java
r3974 r3984 430 430 { 431 431 super.toTransferable(info); 432 info.setArrayDesignId(this.getArrayDesign().getId()); 432 ArrayDesign ad = getArrayDesign(); 433 info.setArrayDesignId(ad == null ? 0 : ad.getId()); 433 434 info.setPlatformId(this.getPlatform().getId()); 434 435 info.setRawDataTypeId(this.getRawDataType().getId()); -
trunk/src/examples/webservices/README
r3961 r3984 26 26 Your password for the BASE web server. 27 27 28 * download.dir 29 Set this option to a valid directory path to enable download of raw data from 30 all raw bioassays. NOTE! Be careful with this option if you have a lot of data. 31 All files from all raw bioassay will be downloaded! 32 28 33 From the command line type: 29 34 … … 36 41 ant -Dservices.url=http://localhost/base/services 37 42 -Dservices.login=mylogin -Dservices.password=mypassword 43 -Ddownload.dir=. 38 44 39 45 -
trunk/src/examples/webservices/build.xml
r3953 r3984 11 11 <property name="services.login" value="root" /> 12 12 <property name="services.password" value="root" /> 13 <!-- set this to a valid directory to enable download of raw data from raw bioassays --> 14 <property name="download.dir" value="" /> 13 15 14 16 <!-- variables for compiling --> … … 49 51 <arg value="${services.login}" /> 50 52 <arg value="${services.password}" /> 53 <arg value="${download.dir}" /> 51 54 <classpath> 52 55 <path refid="classpath" /> -
trunk/src/examples/webservices/src/net/sf/basedb/ws/example/Main.java
r3961 r3984 24 24 package net.sf.basedb.ws.example; 25 25 26 import java.io.File; 27 import java.io.FileOutputStream; 28 import java.io.IOException; 29 import java.io.InputStream; 30 import java.io.OutputStream; 31 26 32 import org.apache.axis2.AxisFault; 27 33 34 import net.sf.basedb.info.DataFileTypeInfo; 28 35 import net.sf.basedb.info.ExperimentInfo; 29 36 import net.sf.basedb.info.ProjectInfo; 30 37 import net.sf.basedb.info.QueryOptions; 38 import net.sf.basedb.info.RawBioAssayInfo; 31 39 import net.sf.basedb.info.VersionInfo; 32 40 import net.sf.basedb.ws.client.ExperimentClient; 33 41 import net.sf.basedb.ws.client.ProjectClient; 42 import net.sf.basedb.ws.client.RawBioAssayClient; 34 43 import net.sf.basedb.ws.client.SessionClient; 35 44 … … 45 54 46 55 This class will connect to the BASE server as specified in the 47 <code>servicesUrl</code>, login, list all projects and experiments 48 the the user has access to and then logout again. 56 <code>servicesUrl</code>, login, list all projects, experiments 57 and raw bioassays the user has access to. It may optionally download 58 data files associated with a raw bioassay. The final step is to logout 59 again. 49 60 50 61 @author nicklas … … 57 68 public static void main(String[] args) 58 69 { 59 if (args.length != 3)70 if (args.length < 3 || args.length > 4) 60 71 { 61 72 showUsage(); … … 65 76 String username = args[1]; 66 77 String password = args[2]; 78 String directory = args.length >= 4 ? args[3] : null; 79 67 80 68 81 Main main = new Main(); … … 78 91 main.listExperiments(); 79 92 System.out.println("------------"); 93 main.listRawBioassays(directory); 94 System.out.println("------------"); 80 95 main.logout(); 81 96 } … … 89 104 private static void showUsage() 90 105 { 91 System.out.println("Usage: Main <url> <login> <password>"); 92 System.out.println(" url : The URL to the BASE webservices server"); 93 System.out.println(" login : The login for an existing user account on the BASE server"); 94 System.out.println(" password : The password for the account"); 106 System.out.println("Usage: Main <url> <login> <password> [directory]"); 107 System.out.println(" url : The URL to the BASE webservices server"); 108 System.out.println(" login : The login for an existing user account on the BASE server"); 109 System.out.println(" password : The password for the account"); 110 System.out.println(" directory : Optional; if specified all raw bioassay data files will be downloaded to this directory"); 95 111 } 96 112 … … 196 212 } 197 213 214 /** 215 List all raw bioassays that the logged in user is has access to. For 216 each raw bioassay, list it's datafiles and download those to the specified 217 directory. If no directory is specified the download is disabled. 218 */ 219 public void listRawBioassays(String directory) 220 throws AxisFault 221 { 222 RawBioAssayClient rc = new RawBioAssayClient(session); 223 RawBioAssayInfo[] rawBioAssays = rc.getRawBioAssays(new QueryOptions()); 224 225 File downloadDir = directory != null ? new File(directory) : null; 226 boolean doDownload = downloadDir != null && downloadDir.isDirectory(); 227 228 if (rawBioAssays == null || rawBioAssays.length == 0) 229 { 230 System.out.println("No raw bioassays found."); 231 } 232 else 233 { 234 System.out.println(rawBioAssays.length + " raw bioassays found"); 235 int i = 0; 236 while (i < rawBioAssays.length) 237 { 238 RawBioAssayInfo info = rawBioAssays[i]; 239 ++i; 240 System.out.println( i + ". " + info.getName() + " [id=" + info.getId() + "]"); 241 242 listDataFiles(rc, info, doDownload ? downloadDir : null); 243 } 244 } 245 } 246 247 /** 248 List all datafiles for a given raw bioassay and download them if a 249 download directory is given. 250 */ 251 public void listDataFiles(RawBioAssayClient rc, RawBioAssayInfo info, File downloadDir) 252 throws AxisFault 253 { 254 DataFileTypeInfo[] files = rc.getDataFileTypes(info.getId(), new QueryOptions()); 255 if (files == null || files.length == 0) 256 { 257 System.out.println(" No data files found."); 258 } 259 else 260 { 261 for (DataFileTypeInfo fileType : files) 262 { 263 System.out.print(" " + fileType.getName()); 264 if (downloadDir != null) 265 { 266 String extension = fileType.getExtension() == null ? "" : "." + fileType.getExtension(); 267 File downloadTo = new File(downloadDir, info.getName() + extension); 268 try 269 { 270 InputStream in = rc.downloadRawDataByType(info.getId(), fileType.getExternalId()); 271 OutputStream out = new FileOutputStream(downloadTo); 272 copy(in, out); 273 out.close(); 274 in.close(); 275 System.out.print("; Download --> " + downloadTo); 276 } 277 catch (IOException ex) 278 { 279 System.out.print("; Download failed: " + ex.getMessage()); 280 } 281 } 282 System.out.println(""); 283 } 284 } 285 } 286 287 /** 288 Copy from InputStream to OutputStream 289 */ 290 public long copy(InputStream in, OutputStream out) 291 throws IOException 292 { 293 int bytes = 0; 294 long totalBytes = 0; 295 byte[] buffer = new byte[1024]; 296 while (bytes != -1) // -1 = end of stream 297 { 298 bytes = in.read(buffer, 0, buffer.length); 299 if (bytes > 0) 300 { 301 totalBytes += bytes; 302 out.write(buffer, 0, bytes); 303 } 304 } 305 return totalBytes; 306 } 307 198 308 199 309 }
Note: See TracChangeset
for help on using the changeset viewer.