Dataset image
Posted:
Thu Aug 12, 2010 7:47 pm
by johnjhufnagle
If I have a Java client and have an image id. What would be the hql and then the api to iterate (ImageI.iterateDatasetLinks() ??) over the containing dataset object...or is that plural? Can an image be associated with more than 1 dataset?
Thank you
John
Re: Dataset image
Posted:
Fri Aug 13, 2010 9:51 am
by cxallan
An image can be associated with more than one dataset. Some example Java code follows:
- Code: Select all
import omero.client;
import omero.api.IQueryPrx;
import omero.api.ServiceFactoryPrx;
import omero.model.Dataset;
import omero.model.Image;
import omero.sys.ParametersI;
public class Example
{
private client client;
private IQueryPrx iq;
public static final long IMAGE_ID = 1L;
public static final String HOST = "localhost";
public static final String USERNAME = "example";
public static final String PASSWORD = "example";
Example() throws Exception
{
client = new client(HOST);
}
public void init() throws Exception
{
ServiceFactoryPrx sf = client.createSession(USERNAME, PASSWORD);
iq = sf.getQueryService();
}
public void run() throws Exception
{
ParametersI params = new ParametersI();
params.addId(IMAGE_ID);
Image i = (Image) iq.findByQuery(
"select i from Image as i " +
"left outer join fetch i.datasetLinks link " +
"join fetch link.parent " +
"where i.id = :id", params);
if (i == null)
{
System.err.println("Unable to find Image id:" + IMAGE_ID);
return;
}
System.out.println("Image: " + i.getName().getValue());
System.out.println("Dataset count: " + i.sizeOfDatasetLinks());
for (Dataset d : i.linkedDatasetList())
{
System.out.println("Dataset name: " + d.getName().getValue());
}
}
public void cleanup() throws Exception
{
client.closeSession();
}
public static void main(String[] args) throws Exception
{
Example e = new Example();
try
{
e.init();
e.run();
}
finally
{
e.cleanup();
}
}
}