Skip to content

Commit

Permalink
Added ICE tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Rylern committed Nov 13, 2023
1 parent 7e8e232 commit 9acacc0
Show file tree
Hide file tree
Showing 15 changed files with 142 additions and 76 deletions.
7 changes: 0 additions & 7 deletions src/main/java/qupath/ext/omero/core/WebClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,6 @@ public ReadOnlyStringProperty getUsername() {
return username;
}

/**
* @return the base URI of the server
*/
public URI getServerURI() {
return apisHandler.getHost();
}

public ObjectProperty<PixelAPI> getSelectedPixelAPI() {
return selectedPixelAPI;
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/qupath/ext/omero/core/WebClients.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static CompletableFuture<WebClient> createClient(String url, String... ar

return existingClient.map(CompletableFuture::completedFuture).orElseGet(() -> WebClient.create(serverURI.get(), args).thenApply(client -> {
if (client.getStatus().equals(WebClient.Status.SUCCESS)) {
ClientsPreferencesManager.addURI(client.getServerURI().toString());
ClientsPreferencesManager.addURI(client.getApisHandler().getWebServerURI().toString());
updateClients(client, Operation.ADD);
}
return client;
Expand Down Expand Up @@ -87,7 +87,7 @@ public static WebClient createClientSync(String url, String... args) {
if (existingClient.isEmpty()) {
var client = WebClient.createSync(serverURI.get(), args);
if (client.getStatus().equals(WebClient.Status.SUCCESS)) {
ClientsPreferencesManager.addURI(client.getServerURI().toString());
ClientsPreferencesManager.addURI(client.getApisHandler().getWebServerURI().toString());
updateClients(client, Operation.ADD);
}

Expand Down Expand Up @@ -142,6 +142,6 @@ private static Optional<URI> getServerURI(String url) {
}

private static Optional<WebClient> getExistingClient(URI uri) {
return clients.stream().filter(e -> e.getServerURI().equals(uri)).findAny();
return clients.stream().filter(e -> e.getApisHandler().getWebServerURI().equals(uri)).findAny();
}
}
10 changes: 5 additions & 5 deletions src/main/java/qupath/ext/omero/core/apis/ApisHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,17 @@ public WebClient getClient() {
}

/**
* @return the base server URI (e.g. <a href="https://idr.openmicroscopy.org">https://idr.openmicroscopy.org</a>)
* @return the web server URI (e.g. <a href="https://idr.openmicroscopy.org">https://idr.openmicroscopy.org</a>)
*/
public URI getHost() {
public URI getWebServerURI() {
return host;
}

/**
* See {@link JsonApi#getHost()}.
* See {@link JsonApi#getServerURI()}.
*/
public String getServerHost() {
return jsonApi.getHost();
public String getServerURI() {
return jsonApi.getServerURI();
}

/**
Expand Down
18 changes: 15 additions & 3 deletions src/main/java/qupath/ext/omero/core/apis/JsonApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,22 @@ public String getToken() {
}

/**
* @return the server host of this server. This is the OMERO server
* host and may be different from the OMERO web host
* <p>
* Get the server URI of this server. This is the <b>OMERO server</b>
* URI and may be different from the <b>OMERO web</b> URI.
* </p>
* <p>
* The returned address is the address used by OMERO web to communicate
* with an OMERO server. If these two entities are running on the same server,
* the returned value of this function may be {@code localhost} or any local IP.
* Therefore, if you can't communicate with the returned value of this function,
* you should be able to communicate with the address of OMERO web (returned by
* {@link ApisHandler#getWebServerURI()}.
* </p>
*
* @return the server host
*/
public String getHost() {
public String getServerURI() {
return serverHost;
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/qupath/ext/omero/core/pixelapis/ice/IceAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class IceAPI implements PixelAPI {

private static final Logger logger = LoggerFactory.getLogger(IceAPI.class);
static final String NAME = "Ice";
private static Boolean gatewayAvailable;
private static boolean gatewayAvailable;
private final WebClient client;

static {
Expand Down Expand Up @@ -98,6 +98,6 @@ public PixelAPIReader createReader(

@Override
public String toString() {
return String.format("Ice API of %s", client.getServerURI());
return String.format("Ice API of %s", client.getApisHandler().getWebServerURI());
}
}
40 changes: 32 additions & 8 deletions src/main/java/qupath/ext/omero/core/pixelapis/ice/IceReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import omero.gateway.model.PixelsData;
import omero.model.ExperimenterGroup;
import qupath.ext.omero.core.WebClient;
import qupath.ext.omero.core.apis.ApisHandler;
import qupath.lib.color.ColorModelFactory;
import qupath.lib.images.servers.ImageChannel;
import qupath.lib.images.servers.PixelType;
Expand All @@ -32,7 +33,7 @@
*/
class IceReader implements PixelAPIReader {

private final Gateway gateway;
private final Gateway gateway = new Gateway(new IceLogger());
private final RawPixelsStorePrx reader;
private final int numberOfResolutionLevels;
private final int nChannels;
Expand All @@ -52,13 +53,7 @@ class IceReader implements PixelAPIReader {
*/
public IceReader(WebClient client, long imageID, List<ImageChannel> channels) throws IOException {
try {
gateway = new Gateway(new IceLogger());
ExperimenterData user = gateway.connect(new LoginCredentials(
client.getUsername().get(),
client.getPassword().map(String::valueOf).orElse(null),
client.getApisHandler().getServerHost(),
client.getApisHandler().getPort()
));
ExperimenterData user = connect(client);

context = new SecurityContext(user.getGroupId());

Expand Down Expand Up @@ -145,6 +140,35 @@ public String toString() {
return String.format("Ice reader for %s", context.getServerInformation());
}

/**
* Attempt to create a connection with the server. The OMERO web host will be
* used, and if not successful, the OMERO server host will be used (see
* {@link ApisHandler#getServerURI()}).
*
* @param client the connection to use
* @return a valid connection
* @throws DSOutOfServiceException when a connection cannot be established
*/
private ExperimenterData connect(WebClient client) throws DSOutOfServiceException {
try {
return gateway.connect(new LoginCredentials(
client.getUsername().get(),
client.getPassword().map(String::valueOf).orElse(null),
client.getApisHandler().getWebServerURI().getHost(),
client.getApisHandler().getPort()
));
} catch (DSOutOfServiceException e) {
System.err.println(client.getApisHandler().getWebServerURI().toString());

return gateway.connect(new LoginCredentials(
client.getUsername().get(),
client.getPassword().map(String::valueOf).orElse(null),
client.getApisHandler().getServerURI(),
client.getApisHandler().getPort()
));
}
}

private Optional<ImageData> getImage(long imageID) throws ExecutionException, DSOutOfServiceException, ServerError {
BrowseFacility browser = gateway.getFacility(BrowseFacility.class);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,6 @@ public PixelAPIReader createReader(

@Override
public String toString() {
return String.format("Web API of %s", client.getServerURI());
return String.format("Web API of %s", client.getApisHandler().getWebServerURI());
}
}
2 changes: 1 addition & 1 deletion src/main/java/qupath/ext/omero/gui/browser/BrowseMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private void setUpListeners() {
for (WebClient client: change.getList()) {
BrowserCommand browserCommand = getBrowserCommand(client);

MenuItem clientMenuItem = new MenuItem(client.getServerURI() + "...");
MenuItem clientMenuItem = new MenuItem(client.getApisHandler().getWebServerURI() + "...");
clientMenuItem.setOnAction(e -> browserCommand.run());
getItems().add(clientMenuItem);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ private void onImportButtonClicked(ActionEvent ignoredEvent) {
}

private void initUI() {
serverHost.setText(client.getServerURI().getHost());
serverHost.setText(client.getApisHandler().getWebServerURI().getHost());

if (client.getSelectedPixelAPI().get().canAccessRawPixels()) {
rawPixelAccess.setText(resources.getString("Browser.Browser.accessRawPixels"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,6 @@ private void populate() {
}

private static boolean clientWithURIExists(String uri) {
return ConnectionsManagerModel.getClients().stream().anyMatch(client -> client.getServerURI().toString().equals(uri));
return ConnectionsManagerModel.getClients().stream().anyMatch(client -> client.getApisHandler().getWebServerURI().toString().equals(uri));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public class Connection extends VBox {
* @throws IOException if an error occurs while creating the pane
*/
public Connection(WebClient client) throws IOException {
this(client, client.getServerURI().toString());
this(client, client.getApisHandler().getWebServerURI().toString());
}

/**
Expand Down Expand Up @@ -141,7 +141,7 @@ private void onConnectionClicked(ActionEvent ignoredEvent) {
resources.getString("ConnectionsManager.Connection.login"),
MessageFormat.format(
resources.getString("ConnectionsManager.Connection.loginSuccessful"),
client.getServerURI(),
client.getApisHandler().getWebServerURI(),
client.getUsername().get()
)
);
Expand Down
4 changes: 1 addition & 3 deletions src/test/java/qupath/ext/omero/OmeroServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,13 @@ public abstract class OmeroServer {
private static final int CLIENT_CREATION_ATTEMPTS = 3;
private static final String OMERO_PASSWORD = "password";
private static final int OMERO_SERVER_PORT = 4064;
private static final boolean dockerAvailable = DockerClientFactory.instance().isDockerAvailable();
private static final GenericContainer<?> postgres;
private static final GenericContainer<?> omeroServer;
private static final GenericContainer<?> omeroWeb;
private static final boolean dockerAvailable;
private static final String analysisFileId;

static {
dockerAvailable = DockerClientFactory.instance().isDockerAvailable();

if (!dockerAvailable || IS_LOCAL_OMERO_SERVER_RUNNING) {
postgres = null;
omeroServer = null;
Expand Down
9 changes: 0 additions & 9 deletions src/test/java/qupath/ext/omero/core/TestWebClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,6 @@ void Check_Client_Username() {
Assertions.assertEquals(expectedUsername, username);
}

@Test
void Check_Client_URI() {
URI expectedURI = URI.create(OmeroServer.getServerURL());

URI uri = client.getServerURI();

Assertions.assertEquals(expectedURI, uri);
}

@Test
void Check_Opened_Images_When_One_Image_Added() {
int expectedSize = client.getOpenedImagesURIs().size() + 1;
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/qupath/ext/omero/core/apis/TestApisHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ static void removeClient() {
void Check_Host() {
URI expectedHost = URI.create(OmeroServer.getServerURL());

URI host = apisHandler.getHost();
URI host = apisHandler.getWebServerURI();

Assertions.assertEquals(expectedHost, host);
}
Expand All @@ -61,7 +61,7 @@ void Check_Host() {
void Check_Server_Host() {
String expectedServerHost = OmeroServer.getServerHost();

String serverHost = apisHandler.getServerHost();
String serverHost = apisHandler.getServerURI();

Assertions.assertEquals(expectedServerHost, serverHost);
}
Expand Down
Loading

0 comments on commit 9acacc0

Please sign in to comment.