Guest User

Untitled

a guest
Nov 20th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 KB | None | 0 0
  1. import ome.formats.OMEROMetadataStoreClient;
  2. import ome.formats.importer.IObservable;
  3. import ome.formats.importer.IObserver;
  4. import ome.formats.importer.ImportCandidates;
  5. import ome.formats.importer.ImportConfig;
  6. import ome.formats.importer.ImportContainer;
  7. import ome.formats.importer.ImportEvent;
  8. import static ome.formats.importer.ImportEvent.IMPORT_DONE;
  9. import ome.formats.importer.ImportLibrary;
  10. import ome.formats.importer.OMEROWrapper;
  11. import ome.formats.importer.cli.ErrorHandler;
  12.  
  13. public class simple_importer {
  14.  
  15. public static ImportConfig config(String[] args) throws Exception {
  16.  
  17. try {
  18. final String host = args[0];
  19. final Integer port = Integer.valueOf(args[1]);
  20. final String username = args[2];
  21. final String password = args[3];
  22. final Long datasetId = Long.valueOf(args[4]);
  23. final String atLeastOneFile = args[5];
  24.  
  25. final ImportConfig config = new ImportConfig();
  26. config.email.set("");
  27. config.sendFiles.set(true);
  28. config.sendReport.set(false);
  29. config.contOnError.set(false);
  30. config.debug.set(false);
  31. config.hostname.set(host);
  32. config.port.set(port);
  33. config.username.set(username);
  34. config.password.set(password);
  35. config.targetClass.set("omero.model.Dataset");
  36. config.targetId.set(datasetId);
  37.  
  38. return config;
  39.  
  40. } catch (Exception e) {
  41. System.err.println("Usage: simple_importer host port user pass id file1 [file2 ...]");
  42. System.err.println("---------------------------------------------------------------");
  43. throw e;
  44. }
  45.  
  46. }
  47.  
  48. public static void main(String[] args) throws Exception {
  49.  
  50. ImportConfig config = config(args);
  51. OMEROMetadataStoreClient store = config.createStore();
  52.  
  53. final String[] paths = new String[args.length-5];
  54. System.arraycopy(args, 5, paths, 0, args.length-5);
  55.  
  56. try {
  57. OMEROWrapper reader = new OMEROWrapper(config);
  58. ImportLibrary library = new ImportLibrary(store, reader);
  59. ErrorHandler handler = new ErrorHandler(config);
  60.  
  61. IObserver status = new IObserver() {
  62. public void update(IObservable importLibrary, ImportEvent event) {
  63. if (event instanceof IMPORT_DONE) {
  64. IMPORT_DONE ev = (IMPORT_DONE) event;
  65. System.err.println("Imported pixels:");
  66. for (omero.model.Pixels p : ev.pixels) {
  67. System.out.println(p.getId().getValue());
  68. }
  69. }
  70. }
  71. };
  72. library.addObserver(status);
  73.  
  74. ImportCandidates candidates = new ImportCandidates(reader, paths, handler);
  75. boolean success = library.importCandidates(config, candidates);
  76. if (!success) {
  77. System.err.println("Failed");
  78. }
  79. } finally {
  80. store.logout();
  81. }
  82. }
  83. }
Add Comment
Please, Sign In to add comment