Skip to content

Commit

Permalink
Split Client and ConnectionHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
ppouchin committed Nov 29, 2024
2 parents cc6b353 + 04a262b commit 51cb0f1
Show file tree
Hide file tree
Showing 7 changed files with 254 additions and 184 deletions.
5 changes: 3 additions & 2 deletions src/main/java/fr/igred/omero/RepositoryObjectWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import fr.igred.omero.client.Browser;
import fr.igred.omero.client.Client;
import fr.igred.omero.client.ConnectionHandler;
import fr.igred.omero.exception.AccessException;
import fr.igred.omero.exception.ExceptionHandler;
import fr.igred.omero.exception.ServiceException;
Expand Down Expand Up @@ -122,7 +123,7 @@ private static List<Pixels> importCandidates(DataObject target, ImportLibrary li
* @throws AccessException Cannot access data.
* @throws IOException Cannot read file.
*/
protected static boolean importImages(Client client, DataObject target, int threads, String... paths)
protected static boolean importImages(ConnectionHandler client, DataObject target, int threads, String... paths)
throws ServiceException, AccessException, IOException {
boolean success;

Expand Down Expand Up @@ -169,7 +170,7 @@ protected static boolean importImages(Client client, DataObject target, int thre
* @throws AccessException Cannot access data.
* @throws IOException Cannot read file.
*/
protected static List<Long> importImage(Client client, DataObject target, String path)
protected static List<Long> importImage(ConnectionHandler client, DataObject target, String path)
throws ServiceException, AccessException, IOException {
ImportConfig config = new ImportConfig();
String type = PojoMapper.getGraphType(target.getClass());
Expand Down
166 changes: 1 addition & 165 deletions src/main/java/fr/igred/omero/client/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,9 @@


import fr.igred.omero.exception.AccessException;
import fr.igred.omero.exception.ExceptionHandler;
import fr.igred.omero.exception.ServiceException;
import ome.formats.OMEROMetadataStoreClient;
import omero.api.IAdminPrx;
import omero.api.IQueryPrx;
import omero.gateway.Gateway;
import omero.gateway.LoginCredentials;
import omero.gateway.exception.DSOutOfServiceException;
import omero.gateway.facility.AdminFacility;
import omero.gateway.facility.BrowseFacility;
import omero.gateway.facility.DataManagerFacility;
Expand All @@ -43,147 +38,7 @@
/**
* Client interface to connect to OMERO, browse through all the data accessible to the user and modify it.
*/
public interface Client extends AdminManager, Browser, DataManager {


/**
* Returns the Gateway.
*
* @return The Gateway.
*/
Gateway getGateway();


/**
* Gets the user id.
*
* @return The user ID.
*/
default long getId() {
return getUser().getId();
}


/**
* Gets the current group ID.
*
* @return The group ID.
*/
default long getCurrentGroupId() {
return getCtx().getGroupID();
}


/**
* Get the ID of the current session
*
* @return See above
*
* @throws ServiceException If the connection is broken, or not logged in
*/
default String getSessionId() throws ServiceException {
return ExceptionHandler.of(getGateway(),
g -> g.getSessionId(getUser().asDataObject()))
.rethrow(DSOutOfServiceException.class,
ServiceException::new,
"Could not retrieve session ID")
.get();
}


/**
* Check if the client is still connected to the server
*
* @return See above.
*/
default boolean isConnected() {
return getGateway().isConnected();
}


/**
* Connects to OMERO using a session ID.
*
* @param hostname Name of the host.
* @param port Port used by OMERO.
* @param sessionId The session ID.
*
* @throws ServiceException Cannot connect to OMERO.
*/
default void connect(String hostname, int port, String sessionId)
throws ServiceException {
connect(new LoginCredentials(sessionId, sessionId, hostname, port));
}


/**
* Connects the user to OMERO.
* <p> Uses the argument to connect to the gateway.
* <p> Connects to the group specified in the argument.
*
* @param hostname Name of the host.
* @param port Port used by OMERO.
* @param username Username of the user.
* @param password Password of the user.
* @param groupID ID of the group to connect.
*
* @throws ServiceException Cannot connect to OMERO.
*/
default void connect(String hostname, int port, String username, char[] password, Long groupID)
throws ServiceException {
LoginCredentials cred = new LoginCredentials(username,
String.valueOf(password),
hostname,
port);
cred.setGroupID(groupID);
connect(cred);
}


/**
* Connects the user to OMERO.
* <p> Uses the argument to connect to the gateway.
* <p> Connects to the default group of the user.
*
* @param hostname Name of the host.
* @param port Port used by OMERO.
* @param username Username of the user.
* @param password Password of the user.
*
* @throws ServiceException Cannot connect to OMERO.
*/
default void connect(String hostname, int port, String username, char[] password)
throws ServiceException {
connect(new LoginCredentials(username,
String.valueOf(password),
hostname,
port));
}


/**
* Connects the user to OMERO. Gets the SecurityContext and the BrowseFacility.
*
* @param credentials User credentials.
*
* @throws ServiceException Cannot connect to OMERO.
*/
void connect(LoginCredentials credentials) throws ServiceException;


/**
* Disconnects the user
*/
void disconnect();


/**
* Change the current group used by the current user;
*
* @param groupId The group ID.
*/
void switchGroup(long groupId);

public interface Client extends AdminManager, Browser, ConnectionHandler, DataManager {

/**
* Gets the {@link BrowseFacility} used to access the data from OMERO.
Expand Down Expand Up @@ -293,25 +148,6 @@ default AdminFacility getAdminFacility() throws ExecutionException {
}


/**
* Creates or recycles the import store.
*
* @return See above.
*
* @throws ServiceException Cannot connect to OMERO.
*/
OMEROMetadataStoreClient getImportStore()
throws ServiceException;


/**
* Closes the import store.
*/
default void closeImport() {
getGateway().closeImport(getCtx(), null);
}


/**
* Returns a Client associated with the provided username.
* <p>The user calling this function needs to have administrator rights.
Expand Down
Loading

0 comments on commit 51cb0f1

Please sign in to comment.