We're Hiring!

CommandLineImporter configuration for group

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.

CommandLineImporter configuration for group

Postby derekeh » Fri Apr 05, 2019 10:43 am

Hi,
From my java app I am using the ome.formats.importer.cli.CommandLineImporter to upload images.
I've included my code below.
The user belongs to 2 groups. Private and Public. The default is the private one.
If the user uploads to the private group, do not need to set the groupId and everthing works ok.

If, however, I try to upload to the public group by adding the public groupId to the configuration I get a "Failed to load target" ERROR.
How do I configure the cli to be able to upload to the public group?

Thanks in advance
Derek

Code: Select all
public String upload_via_omero_cli(String[] paths, long datasetID, boolean isPublic) throws Exception {
            String RET="OK";
            ImportConfig config = new ImportConfig();
            long public_group_id=53;
            config.email.set("");
            config.sendFiles.set(true);
            config.sendReport.set(false);
            config.contOnError.set(false);
            config.debug.set(false);
            config.hostname.set(props.getProperty("server"));
            config.port.set(Integer.parseInt(props.getProperty("port")));
            config.username.set(props.getProperty("db_user"));
            config.password.set(props.getProperty("db_passwd"));
            config.target.set("Dataset:"+datasetID);
       if(isPublic)
         config.group.set(public_group_id);
           
            boolean setting=false;
            CommandLineImporter cli=null;
            try {
                cli = new CommandLineImporter(config,paths,setting);
                cli.start();
            }
            catch(Exception e){RET="ERROR: "+e.getMessage();}
            finally {
                if(cli!=null)
                    cli.cleanup();
            }
            return RET;
    }
derekeh
 
Posts: 31
Joined: Mon Feb 12, 2018 12:00 pm

Re: CommandLineImporter configuration for group

Postby derekeh » Fri Apr 05, 2019 10:44 am

Using Omero 5.4.0
derekeh
 
Posts: 31
Joined: Mon Feb 12, 2018 12:00 pm

Re: CommandLineImporter configuration for group

Postby jmoore » Fri Apr 05, 2019 10:49 am

Hi Derek,

the exception is a known issue that will be fixed in the upcoming 5.5.0. See:


In your case, which group is the Dataset in?
~Josh
User avatar
jmoore
Site Admin
 
Posts: 1591
Joined: Fri May 22, 2009 1:29 pm
Location: Germany

Re: CommandLineImporter configuration for group

Postby derekeh » Fri Apr 05, 2019 11:08 am

Hi Josh,
Thanks for replying.
If my dataset is in the public group and I configure with the public_group_id I get the error.
If I move the dataset to the private group and do not configure the public_group_id it works.

Derek
derekeh
 
Posts: 31
Joined: Mon Feb 12, 2018 12:00 pm

Re: CommandLineImporter configuration for group

Postby derekeh » Mon Apr 08, 2019 9:52 am

Any suggestions as to how I might fix this?
Is there a hook to attach a new securityContext(groupId) to the CLI?

Anything?
Derek
derekeh
 
Posts: 31
Joined: Mon Feb 12, 2018 12:00 pm

Re: CommandLineImporter configuration for group

Postby jmoore » Mon Apr 08, 2019 10:59 am

Hi Derek,

how are you creating your session before running the code? If I were going to try this myself, I'd likely start by creating the session from the command-line, and then handing it off to the Java code. In that case, I could choose which group I wanted to use:

Code: Select all
$ bin/omero login USER@localhost
Created session for USER@localhost. Idle timeout: 10 min. Current group: DEFAULTGROUP
$ bin/omero sessions group 805
Using session for USER@localhost. Idle timeout: 10 min. Current group: DEFAULTGROUP
Group 'DEFAULTGROUP' (id=804) switched to 'OTHERGROUP' (id=805)


Is changing the group at the session level an option for you? Or are you re-using the session between multiple activities?

~J.
User avatar
jmoore
Site Admin
 
Posts: 1591
Joined: Fri May 22, 2009 1:29 pm
Location: Germany

Re: CommandLineImporter configuration for group

Postby derekeh » Mon Apr 08, 2019 12:20 pm

Well that has opened up a whole lot of questions....

Before I go into that can we clarify that in the java code, using config.group.set(group_id) :
1. Is meant to configure the command Line Importer to use the [group_id]
2. It doesn't work

Thanks
Derek
derekeh
 
Posts: 31
Joined: Mon Feb 12, 2018 12:00 pm

Re: CommandLineImporter configuration for group

Postby jmoore » Mon Apr 08, 2019 1:38 pm

derekeh wrote:1. Is meant to configure the command Line Importer to use the [group_id]
2. It doesn't work


In general, yes. You're not misusing the API. Unfortunately, it only specifies the client's active group, where if I follow what's going on, the server-side session hasn't been updated and therefore the Dataset isn't being found. I'd imagine it's a fixable bug, but not without a new release, so it would seem you'll need a workaround.

~Josh.
User avatar
jmoore
Site Admin
 
Posts: 1591
Joined: Fri May 22, 2009 1:29 pm
Location: Germany

Re: CommandLineImporter configuration for group

Postby derekeh » Tue Apr 09, 2019 7:27 am

OK
how are you creating your session before running the code?

I wasn't creating a session specifically. I presumed that configuring and starting the java CLI did that under the hood.
Well, it must because it works with the default group.

I'd likely start by creating the session from the command-line,

The end user will not have access to /bin/omero. The code is deployed as a web app.
I'd prefer to complete the whole task via java rather than invoke external scripts to run /bin/omero - spirit of encapsulation and all that.....

In all other transactions in my code, eg creating projects, datasets etc I use the Gateway and can change the user's group with:
Code: Select all
ExperimenterData user = gateway.connect(loginCredentials);
new SecurityContext(user.getGroupId())


I can get the sessionID from
Code: Select all
gateway.getSession(user)


I read somewhere (escapes me right now) that I can reuse the connection by supplying the sessionID in place of the username and null for the password.

Can I use this information somehow to invoke the CLI (or alternatively via importLibrary.importCandidates)?
Or any other way to import the images to a non default group?

Lots of questions I know but I'm running out of possible scenarios and of course the ability to switch groups (private/public) to upload images to is rather crucial.

Thanks again for your help.
Derek
derekeh
 
Posts: 31
Joined: Mon Feb 12, 2018 12:00 pm

Re: CommandLineImporter configuration for group

Postby jmoore » Tue Apr 09, 2019 8:12 am

derekeh wrote:I wasn't creating a session specifically. I presumed that configuring and starting the java CLI did that under the hood. Well, it must because it works with the default group.


Indeed.

The end user will not have access to /bin/omero. The code is deployed as a web app.
I'd prefer to complete the whole task via java rather than invoke external scripts to run /bin/omero - spirit of encapsulation and all that.....


Of course. But this gives you an easy way to test if you'd like. We'll be happy to provide the same in Java.

In all other transactions in my code, eg creating projects, datasets etc I use the Gateway and can change the user's group with:
Code: Select all
ExperimenterData user = gateway.connect(loginCredentials);
new SecurityContext(user.getGroupId())



This does roughly the same as the config.group.set call which is to set the client-side group. My hunch is that you will need to create your session with the right server-side group to workaround your current issue.


I read somewhere (escapes me right now) that I can reuse the connection by supplying the sessionID in place of the username and null for the password.


Correct, or a potential alternative would be to set the group on the server-session which is safe as long as the session is not being re-used by multiple clients, which is why I was asking where your session was coming from.

For example, you might try this:

Code: Select all
import ome.formats.importer.*;

public class login {
  public final static String HOST = "YOURHOST";
  public final static String PORT = "4064";
  public static void main(String[] args) throws Exception {
    omero.client c = new omero.client(new String[]{"--omero.host="+HOST, "--omero.port="+PORT,"--omero.group=OTHERGROUP"});
    try {
      c.createSession("USER", "PASSWORD");
      System.out.println("Session:" + c.getSessionId());
      System.out.println("Group:" + c.getSession().getAdminService().getEventContext().groupId);
      run(c.getSessionId());
    } finally {
      c.__del__();
    }
  }

  public static void run(String session) throws Exception {
    ImportConfig config = new ImportConfig();
    config.sessionKey.set(session);
    config.hostname.set(HOST);
    config.port.set(Integer.parseInt(PORT));
    ome.formats.OMEROMetadataStoreClient store = config.createStore();
    try {
      System.out.println(store);
    } finally {
      store.logout();
    }
  }

}


where in the run method you'd make use of the sessionKey in your current code.
~J
User avatar
jmoore
Site Admin
 
Posts: 1591
Joined: Fri May 22, 2009 1:29 pm
Location: Germany

Next

Return to Developer Discussion

Who is online

Users browsing this forum: No registered users and 1 guest