This is an example of how to load many images while using IContainer.loadContainerHierarchy.
See https://www.openmicroscopy.org/community/viewtopic.php?f=6&t=3341
*.class | |
libs |
This is an example of how to load many images while using IContainer.loadContainerHierarchy.
See https://www.openmicroscopy.org/community/viewtopic.php?f=6&t=3341
CLASSPATH?=.:$(shell ls libs/*.jar | perl -pe 's/\s/:/g') | |
mle: mle.class | |
java -cp $(CLASSPATH) mle | |
mle.class: mle.java | |
javac -cp $(CLASSPATH) mle.java | |
.PHONY: mle | |
import omero.*; | |
import omero.api.*; | |
import omero.model.*; | |
import omero.sys.*; | |
import java.io.*; | |
import java.util.*; | |
import pojos.*; | |
import Glacier2.*; | |
import static omero.rtypes.*; | |
public class mle { | |
// | |
// http://www.openmicroscopy.org/site/support/omero4/developers/Java.html | |
// to retrieve 'projects', 'datasets', or 'images'. | |
// The error comes up when processing 'project', so i paste a simplified version. | |
// | |
// Jparse & JparseInfo for parsing parameters (not shown here). " | |
// Again, it works fine with most users but not this one (20G jpeg). | |
static int batchSize = 3; | |
static omero.client myClient; | |
static ServiceFactoryPrx myEntry; | |
public static void makeProjects() throws ServerError | |
{ | |
Project p = new ProjectI(); | |
p.setName(rstring("test")); | |
for (int i = 0; i < 10; i++) { | |
Dataset d = new DatasetI(); | |
d.setName(rstring("test:"+i)); | |
for (int j = 0; j < 10; j++) { | |
Image img = new ImageI(); | |
img.setName(rstring("test:"+i+":"+j)); | |
img.setAcquisitionDate(rtime(0)); | |
d.linkImage(img); | |
} | |
p.linkDataset(d); | |
} | |
p = (Project) myEntry.getUpdateService().saveAndReturnObject(p); | |
System.out.println("Made project: " + p.getId().getValue()); | |
} | |
public static void retrieveProjects (long lon_userId) throws IOException, ServerError | |
{ | |
IContainerPrx proxy = myEntry.getContainerService(); | |
ParametersI param = new ParametersI(); | |
long userId =lon_userId; // entryUnencrypted.getAdminService().getEventContext().userId; | |
param.exp(omero.rtypes.rlong(userId)); | |
param.noLeaves(); //indicate to load the images | |
//param.noLeaves(); //no images loaded, this is the default value. | |
List<IObject> results = proxy.loadContainerHierarchy(Project.class.getName(), new ArrayList<Long>(), param); | |
//You can directly interact with the IObject or the Pojos object. | |
//Follow interaction with the Pojos. | |
Iterator<IObject> i = results.iterator(); | |
ProjectData project; | |
Set<DatasetData> datasets; | |
Iterator<DatasetData> j; | |
DatasetData dataset; | |
while (i.hasNext()) { | |
project = new ProjectData((Project) i.next()); // ONE PROJECT; | |
String vProject = project.getName(); | |
Long vProjectId = project.getId(); | |
System.out.print("start retrieving project:"+vProject+".\n"); | |
datasets = project.getDatasets(); // ALL DATASETS IN ONE PROJECT; | |
j = datasets.iterator(); | |
while (j.hasNext()) { | |
dataset = j.next(); // ONE DATASET IN ONE PROJECT; | |
String vDataSet = dataset.getName(); | |
Long vDataSetId = dataset.getId(); | |
System.out.print("start retrieving dataset:"+vDataSet+".\n"); | |
ParametersI param2 = new ParametersI(); | |
param2.page(0, batchSize); | |
int whichPage = 1; | |
List<Long> dsIds = new ArrayList<Long>(); | |
dsIds.add(vDataSetId); | |
while (true) { | |
List<Image> images = proxy.getImages(Dataset.class.getName(), dsIds, param2); | |
// handle images | |
System.out.println(String.format("\tLoaded %s images in page %s", | |
images.size(), whichPage)); | |
// prepare next batch | |
if (images.size() == 0) { | |
break; | |
} else { | |
int newOffset = param2.getOffset().getValue() + batchSize; | |
param2.page(newOffset, batchSize); | |
whichPage++; | |
} | |
} | |
} // end while j ; | |
} // end while i; | |
} // end projects | |
public static void getDataForAnnot(String argv[]) throws ServerError, IOException | |
{ | |
try { | |
// Make use of ICE_CONFIG properties | |
myClient = new client(); | |
myEntry = myClient.createSession(); | |
long userId =myEntry.getAdminService().getEventContext().userId; | |
long groupId = myEntry.getAdminService().getEventContext().groupId; | |
System.out.print("The connection is set up and userId is:"+userId+"**.\n\n"); | |
System.out.print("groupId is:"+groupId+"**.\n\n"); | |
// System.out.print("***********************.\n\n"); | |
// System.out.print("********************888888**.\n\n"); | |
// makeProjects(); | |
retrieveProjects (userId); | |
// retrieveDatasets (userId); | |
} | |
catch (ServerError e) {System.err.print(e);} | |
catch (CannotCreateSessionException c) {System.err.print(c);} | |
catch (PermissionDeniedException p) {System.err.print(p);} | |
finally { | |
myClient.closeSession(); | |
} | |
} // end of forPivot; | |
public static void main(String argv[]) throws ServerError, IOException | |
{ | |
getDataForAnnot(argv); | |
System.exit(0); | |
} // end of main; | |
} |