Skip to content

Commit abb2ebf

Browse files
committed
Cleaned code
1 parent fe12fde commit abb2ebf

File tree

20 files changed

+699
-525
lines changed

20 files changed

+699
-525
lines changed

src/main/java/qupath/ext/omero/core/WebClient.java

Lines changed: 146 additions & 170 deletions
Large diffs are not rendered by default.

src/main/java/qupath/ext/omero/core/WebClients.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,16 @@ public static WebClient createClientSync(String url, WebClient.Authentication au
123123
}
124124
}
125125

126+
/**
127+
* Retrieve the client corresponding to the provided uri.
128+
*
129+
* @param uri the web server URI of the client to retrieve
130+
* @return the client corresponding to the URI, or an empty Optional if not found
131+
*/
132+
public static Optional<WebClient> getClientFromURI(URI uri) {
133+
return clients.stream().filter(client -> client.getApisHandler().getWebServerURI().equals(uri)).findAny();
134+
}
135+
126136
/**
127137
* Close the given client connection. The function may return
128138
* before the connection is actually closed.

src/main/java/qupath/ext/omero/core/apis/ApisHandler.java

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package qupath.ext.omero.core.apis;
22

33
import com.drew.lang.annotations.Nullable;
4-
import javafx.beans.property.*;
4+
import javafx.beans.property.ReadOnlyBooleanProperty;
5+
import javafx.beans.property.ReadOnlyIntegerProperty;
56
import org.slf4j.Logger;
67
import org.slf4j.LoggerFactory;
78
import qupath.ext.omero.core.entities.annotations.AnnotationGroup;
@@ -14,13 +15,13 @@
1415
import qupath.ext.omero.core.entities.search.SearchQuery;
1516
import qupath.ext.omero.core.entities.search.SearchResult;
1617
import qupath.ext.omero.core.entities.shapes.Shape;
17-
import qupath.lib.images.servers.*;
18-
import qupath.ext.omero.core.WebClient;
1918
import qupath.ext.omero.core.WebUtilities;
2019
import qupath.ext.omero.core.entities.imagemetadata.ImageMetadataResponse;
2120
import qupath.ext.omero.core.entities.permissions.Group;
2221
import qupath.ext.omero.core.entities.permissions.Owner;
2322
import qupath.ext.omero.core.entities.repositoryentities.serverentities.image.Image;
23+
import qupath.lib.images.servers.PixelType;
24+
import qupath.lib.images.servers.TileRequest;
2425

2526
import java.awt.image.BufferedImage;
2627
import java.net.URI;
@@ -75,12 +76,11 @@ private ApisHandler(URI host, JsonApi jsonApi, boolean canSkipAuthentication) {
7576
* <p>Attempt to create a request handler.</p>
7677
* <p>This function is asynchronous.</p>
7778
*
78-
* @param client the corresponding web client
7979
* @param host the base server URI (e.g. <a href="https://idr.openmicroscopy.org">https://idr.openmicroscopy.org</a>)
8080
* @return a CompletableFuture with the request handler, an empty Optional if an error occurred
8181
*/
82-
public static CompletableFuture<Optional<ApisHandler>> create(WebClient client, URI host) {
83-
return JsonApi.create(client, host).thenApplyAsync(jsonApi -> {
82+
public static CompletableFuture<Optional<ApisHandler>> create(URI host) {
83+
return JsonApi.create(host).thenApplyAsync(jsonApi -> {
8484
if (jsonApi.isPresent()) {
8585
try {
8686
return Optional.of(new ApisHandler(host, jsonApi.get(), jsonApi.get().canSkipAuthentication().get()));
@@ -280,17 +280,27 @@ public CompletableFuture<Optional<Image>> getImage(long imageID) {
280280
}
281281

282282
/**
283-
* See {@link JsonApi#getNumberOfOrphanedImages()}.
283+
* <p>Attempt to get the number of orphaned images of this server.</p>
284+
*
285+
* @return a CompletableFuture with the number of orphaned images, or 0 if it couldn't be retrieved
284286
*/
285287
public CompletableFuture<Integer> getNumberOfOrphanedImages() {
286-
return jsonApi.getNumberOfOrphanedImages();
288+
return getOrphanedImagesIds().thenApply(jsonApi::getNumberOfOrphanedImages);
287289
}
288290

289291
/**
290-
* See {@link JsonApi#populateOrphanedImagesIntoList(List)}.
292+
* <p>
293+
* Populate all orphaned images of this server to the list specified in parameter.
294+
* This function populates and doesn't return a list because the number of images can
295+
* be large, so this operation can take tens of seconds.
296+
* </p>
297+
* <p>The list can be updated from any thread.</p>
298+
*
299+
* @param children the list which should be populated by the orphaned images. It should
300+
* be possible to add elements to this list
291301
*/
292302
public void populateOrphanedImagesIntoList(List<Image> children) {
293-
jsonApi.populateOrphanedImagesIntoList(children);
303+
getOrphanedImagesIds().thenAccept(orphanedImageIds -> jsonApi.populateOrphanedImagesIntoList(children, orphanedImageIds));
294304
}
295305

296306
/**

0 commit comments

Comments
 (0)