We're Hiring!

Loading Shared Image Thumbnail w/ Java Client?

General and open developer discussion about using OMERO APIs from C++, Java, Python, Matlab and more! Please new questions at https://forum.image.sc/tags/omero
Please note:
Historical discussions about OMERO. Please look for and ask new questions at https://forum.image.sc/tags/omero

If you are having trouble with custom code, please provide a link to a public repository, ideally GitHub.

Loading Shared Image Thumbnail w/ Java Client?

Postby bbimber » Mon Sep 17, 2018 5:14 pm

Hello,

I am extremely new to omero. We have an omero server running 5.4.7, and I'm, using the java client to try to load thumbnails. The image in question is a shared image (not owned by my user), and I am trying to load using the numeric ID. I am following the pattern from this github repo (https://github.com/ome/minimal-omero-cl ... ction.java). The code below doesnt seem to be able to find the ImageData by ID:

//I did not copy the full code here, but it's similar to the github example
SecurityContext ctx = connect(gateway, url);

BrowseFacility browse = gateway.getFacility(BrowseFacility.class);

//neither of these work. findObject() is non-null (but seems like some kind of empty object placeholder), and getImage() returns null
ImageData image = browse.findObject(ctx, ImageData.class, imageId, true);
//ImageData image = browse.getImage(ctx, imageId);

//this will error
PixelsData pixels = image.getDefaultPixels();
ThumbnailStorePrx store = gateway.getThumbnailService(ctx);
store.setPixelsId(pixels.getId());

Can you suggest any debugging steps I should take? Thanks in advance.
bbimber
 
Posts: 8
Joined: Thu Oct 29, 2015 4:00 pm

Re: Loading Shared Image Thumbnail w/ Java Client?

Postby jmoore » Wed Sep 19, 2018 12:01 pm

Hi Benjamin,

is it possible that you aren't logged into the group which the image is in? This sounds similar to http://lists.openmicroscopy.org.uk/pipe ... 03886.html

I added your code as an example to https://github.com/ome/minimal-omero-cl ... 250c3d7R91 and no exception is thrown:

Code: Select all
Connected as testUser
Ready to get thumbnail


Let us know how things go.
~Josh
User avatar
jmoore
Site Admin
 
Posts: 1591
Joined: Fri May 22, 2009 1:29 pm
Location: Germany

Re: Loading Shared Image Thumbnail w/ Java Client?

Postby bbimber » Wed Sep 19, 2018 4:21 pm

Thanks for the reply, and that is almost certainly it, but I would like to understand the limits a little more.

Our scenario is that we have multiple users/groups potentially saving images on OMERO. We have a service account (which is what this API is using), that should be able to read anything (and it can read these if I log into the omero webapp). As it stands, the java client only has the omero ID of the image. It does not know which user/group owns that image. I would ideally like to write code that grabs this thumbnail based on ID with minimal querying, but obviously it needs to be robust.

If all my code knows is that omero ID, can I query to find some object that will tell me what group it belongs to? Is there another pattern I should be following here?

Thanks, and apologies if I'm missing something obvious.
bbimber
 
Posts: 8
Joined: Thu Oct 29, 2015 4:00 pm

Re: Loading Shared Image Thumbnail w/ Java Client?

Postby bbimber » Wed Sep 19, 2018 11:18 pm

Also, I had hoped BrowseFacility.findObject() would let me do this, since it has an 'allGroups' argument:

ImageData image1 = browse.findObject(ctx, ImageData.class, imageId, true);

This returns a non-null ImageData object, but if you inspect it virtually all the properties are null. Do I need to do something to force that to load itself? image1.isLoaded() returns true; however, something isnt right. Group ownership is defintiely the problem, but I'm not sure how to fix it. Here's an example:

ImageData image;
try
{
//try to find it for the current user
image = browse.getImage(ctx, imageId, params);
}
catch (Exception e)
{
//if not found above (which throws a NoSuchElementException), try to locate the object for all groups
image = browse.findObject(ctx, ImageData.class, imageId, true);
Long groupId = image.getGroupId();
if (groupId > 0 && groupId != ctx.getGroupID())
{
//this returns a valid image
image = browse.getImage(new SecurityContext(groupId), imageId, params);

//this is non-null (good)
PixelsData pixels = image.getDefaultPixels();

ThumbnailStorePrx store = gateway.getThumbnailService(ctx);
store.setPixelsId(pixels.getId());

//the problem is that we get a security exception since the alternate group lacks permissions to load:
byte[] bytes = store.getThumbnail(omero.rtypes.rint(96), omero.rtypes.rint(96));
}
}

I must be missing something here, since through the Omero web application, I can log in with the same user, toggle to this shared group and view these images.
bbimber
 
Posts: 8
Joined: Thu Oct 29, 2015 4:00 pm

Re: Loading Shared Image Thumbnail w/ Java Client?

Postby mtbc » Thu Sep 20, 2018 11:05 am

Dear Benjamin,

You're nearly there. It's a great help that you share your code. The SecurityContext you made from ExperimenterData.getGroupId() is for the user's default group but they may be able to read data from other groups. By passing allGroups==true you managed to get the group ID for the image. Now create a new SecurityContext using that group ID for use as the ctx variable that you pass to the subsequent calls back to the server to work with the image and you should find that your code now works. For instance,
Code: Select all
... use allGroups to get image ...
// now use the context of the image's group
ctx = new SecurityContext(image.getGroupId());
... do image stuff ...

Cheers,
Mark
User avatar
mtbc
Team Member
 
Posts: 282
Joined: Tue Oct 23, 2012 10:59 am
Location: Dundee, Scotland

Re: Loading Shared Image Thumbnail w/ Java Client?

Postby bbimber » Thu Sep 20, 2018 3:03 pm

Great - that worked. Thanks for the help.
bbimber
 
Posts: 8
Joined: Thu Oct 29, 2015 4:00 pm


Return to Developer Discussion

Who is online

Users browsing this forum: Bing [Bot] and 1 guest

cron