It looks like you're trying to use the Insight code. That's quite complex, because it deals with a lot of use cases (importing for different users, creating projects/datasets automatically, etc.).
Here's a simple example for importing images into an already existing dataset (with id 1 in that case) using the OMEROMetadataStoreClient from the Java API directly:
- Code: Select all
public void uploadImages(String... paths) {
ImportConfig config = new ome.formats.importer.ImportConfig();
config.email.set("");
config.sendFiles.set(true);
config.sendReport.set(false);
config.contOnError.set(false);
config.debug.set(false);
config.hostname.set("localhost");
config.port.set(4064);
config.username.set("root");
config.password.set("omero");
config.targetClass.set("omero.model.Dataset");
config.targetId.set(1L);
OMEROMetadataStoreClient store;
try {
store = config.createStore();
store.logVersionInfo(config.getIniVersionNumber());
OMEROWrapper reader = new OMEROWrapper(config);
ImportLibrary library = new ImportLibrary(store, reader);
ErrorHandler handler = new ErrorHandler(config);
library.addObserver(new LoggingImportMonitor());
ImportCandidates candidates = new ImportCandidates(reader, paths, handler);
reader.setMetadataOptions(new DefaultMetadataOptions(MetadataLevel.ALL));
library.importCandidates(config, candidates);
store.logout();
} catch (Exception e) {
e.printStackTrace();
}
}
I'll also add this to the Java examples in our developer documentation, unfortunately a example for this task is still missing in the documentation for now.
Regards,
Dominik