Skip to content

Commit

Permalink
Replace Client with interface intersections
Browse files Browse the repository at this point in the history
  • Loading branch information
ppouchin committed Dec 1, 2024
1 parent c95d937 commit 4eb1ba7
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 49 deletions.
30 changes: 19 additions & 11 deletions src/main/java/fr/igred/omero/Annotatable.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import fr.igred.omero.annotations.TagAnnotation;
import fr.igred.omero.client.BasicBrowser;
import fr.igred.omero.client.BasicDataManager;
import fr.igred.omero.client.Client;
import fr.igred.omero.client.DataManager;
import fr.igred.omero.exception.AccessException;
import fr.igred.omero.exception.ServiceException;
import fr.igred.omero.util.ReplacePolicy;
Expand Down Expand Up @@ -68,7 +68,7 @@ public interface Annotatable extends RemoteObject {
* @throws AccessException Cannot access data.
* @throws ExecutionException A Facility can't be retrieved or instantiated.
*/
default <A extends Annotation> boolean isLinked(BasicBrowser browser, A annotation)
default <A extends Annotation> boolean isLinked(BasicBrowser browser, A annotation)
throws ServiceException, AccessException, ExecutionException {
return getAnnotations(browser).stream().anyMatch(a -> a.getId() == annotation.getId());
}
Expand Down Expand Up @@ -144,7 +144,8 @@ default void link(BasicDataManager dm, Annotation... annotations)
* @throws AccessException Cannot access data.
* @throws ExecutionException A Facility can't be retrieved or instantiated.
*/
default void linkIfNotLinked(Client client, Annotation... annotations)
default <C extends BasicBrowser & BasicDataManager>
void linkIfNotLinked(C client, Annotation... annotations)
throws ServiceException, AccessException, ExecutionException {
List<Long> annotationIds = getAnnotationData(client).stream()
.map(DataObject::getId)
Expand Down Expand Up @@ -336,7 +337,7 @@ default List<RatingAnnotation> getRatings(BasicBrowser browser)
* @throws ExecutionException A Facility can't be retrieved or instantiated.
* @throws InterruptedException The thread was interrupted.
*/
void rate(Client client, int rating)
<C extends BasicBrowser & DataManager> void rate(C client, int rating)
throws ServiceException, AccessException, ExecutionException, InterruptedException;


Expand Down Expand Up @@ -405,7 +406,8 @@ default void addTable(BasicDataManager dm, TableWrapper table)
* @throws ExecutionException A Facility can't be retrieved or instantiated.
* @throws InterruptedException The thread was interrupted.
*/
void addAndReplaceTable(Client client, TableWrapper table, ReplacePolicy policy)
<C extends BasicBrowser & BasicDataManager>
void addAndReplaceTable(C client, TableWrapper table, ReplacePolicy policy)
throws ServiceException, AccessException, ExecutionException, InterruptedException;


Expand All @@ -421,7 +423,8 @@ void addAndReplaceTable(Client client, TableWrapper table, ReplacePolicy policy)
* @throws ExecutionException A Facility can't be retrieved or instantiated.
* @throws InterruptedException The thread was interrupted.
*/
default void addAndReplaceTable(Client client, TableWrapper table)
default <C extends BasicBrowser & BasicDataManager>
void addAndReplaceTable(C client, TableWrapper table)
throws ServiceException, AccessException, ExecutionException, InterruptedException {
addAndReplaceTable(client, table, ReplacePolicy.DELETE_ORPHANED);
}
Expand Down Expand Up @@ -506,7 +509,8 @@ default long addFile(BasicDataManager dm, File file)
* @throws ExecutionException A Facility can't be retrieved or instantiated.
* @throws InterruptedException The thread was interrupted.
*/
long addAndReplaceFile(Client client, File file, ReplacePolicy policy)
<C extends BasicBrowser & BasicDataManager>
long addAndReplaceFile(C client, File file, ReplacePolicy policy)
throws ExecutionException, InterruptedException, AccessException, ServiceException;


Expand All @@ -524,7 +528,8 @@ long addAndReplaceFile(Client client, File file, ReplacePolicy policy)
* @throws ExecutionException A Facility can't be retrieved or instantiated.
* @throws InterruptedException The thread was interrupted.
*/
default long addAndReplaceFile(Client client, File file)
default <C extends BasicBrowser & BasicDataManager>
long addAndReplaceFile(C client, File file)
throws ExecutionException, InterruptedException, AccessException, ServiceException {
return addAndReplaceFile(client, file, ReplacePolicy.DELETE_ORPHANED);
}
Expand Down Expand Up @@ -557,7 +562,8 @@ List<FileAnnotation> getFileAnnotations(BasicBrowser browser)
* @throws ExecutionException A Facility can't be retrieved or instantiated.
* @throws InterruptedException If block(long) does not return.
*/
<A extends Annotation> void unlink(Client client, A annotation)
<A extends Annotation, C extends BasicBrowser & BasicDataManager>
void unlink(C client, A annotation)
throws ServiceException, AccessException, ExecutionException, InterruptedException;


Expand All @@ -573,7 +579,8 @@ <A extends Annotation> void unlink(Client client, A annotation)
* @throws ExecutionException A Facility can't be retrieved or instantiated.
* @throws InterruptedException If block(long) does not return.
*/
<A extends Annotation> void unlink(Client client, Collection<A> annotations)
<A extends Annotation, C extends BasicBrowser & BasicDataManager>
void unlink(C client, Collection<A> annotations)
throws ServiceException, AccessException, ExecutionException, InterruptedException;


Expand Down Expand Up @@ -621,7 +628,8 @@ List<Annotation> getAnnotations(BasicBrowser browser)
* @throws AccessException Cannot access data.
* @throws ExecutionException A Facility can't be retrieved or instantiated.
*/
default void copyAnnotationLinks(Client client, Annotatable object)
default <C extends BasicBrowser & BasicDataManager>
void copyAnnotationLinks(C client, Annotatable object)
throws AccessException, ServiceException, ExecutionException {
List<AnnotationData> newAnnotations = object.getAnnotationData(client);
List<AnnotationData> oldAnnotations = this.getAnnotationData(client);
Expand Down
25 changes: 14 additions & 11 deletions src/main/java/fr/igred/omero/AnnotatableWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import fr.igred.omero.annotations.TagAnnotationWrapper;
import fr.igred.omero.client.BasicBrowser;
import fr.igred.omero.client.BasicDataManager;
import fr.igred.omero.client.Client;
import fr.igred.omero.client.DataManager;
import fr.igred.omero.exception.AccessException;
import fr.igred.omero.exception.ServiceException;
import fr.igred.omero.util.ReplacePolicy;
Expand Down Expand Up @@ -253,7 +253,8 @@ public List<RatingAnnotation> getRatings(BasicBrowser browser, List<Long> userId
* @throws InterruptedException The thread was interrupted.
*/
@Override
public void rate(Client client, int rating)
public <C extends BasicBrowser & DataManager>
void rate(C client, int rating)
throws ServiceException, AccessException, ExecutionException, InterruptedException {
List<Long> userIds = singletonList(client.getCtx().getExperimenter());

Expand Down Expand Up @@ -311,7 +312,8 @@ public int getMyRating(BasicBrowser browser)
* @throws InterruptedException The thread was interrupted.
*/
@Override
public void addAndReplaceTable(Client client, TableWrapper table, ReplacePolicy policy)
public <C extends BasicBrowser & BasicDataManager>
void addAndReplaceTable(C client, TableWrapper table, ReplacePolicy policy)
throws ServiceException, AccessException, ExecutionException, InterruptedException {
String error = "Cannot add table to " + this;
Collection<FileAnnotation> tables = wrap(call(client.getTablesFacility(),
Expand Down Expand Up @@ -384,7 +386,7 @@ public TableWrapper getTable(BasicDataManager dm, Long fileId)
* @throws InterruptedException The thread was interrupted.
*/
@Override
public long addAndReplaceFile(Client client, File file, ReplacePolicy policy)
public <C extends BasicBrowser & BasicDataManager> long addAndReplaceFile(C client, File file, ReplacePolicy policy)
throws ExecutionException, InterruptedException, AccessException, ServiceException {
List<FileAnnotation> files = getFileAnnotations(client);

Expand Down Expand Up @@ -457,7 +459,7 @@ public List<FileAnnotation> getFileAnnotations(BasicBrowser browser)
* @throws InterruptedException If block(long) does not return.
*/
@Override
public <A extends Annotation> void unlink(Client client, A annotation)
public <A extends Annotation, C extends BasicBrowser & BasicDataManager> void unlink(C client, A annotation)
throws ServiceException, AccessException, ExecutionException, InterruptedException {
removeLink(client, annotationLinkType(), annotation.getId());
}
Expand All @@ -476,7 +478,8 @@ public <A extends Annotation> void unlink(Client client, A annotation)
* @throws InterruptedException If block(long) does not return.
*/
@Override
public <A extends Annotation> void unlink(Client client, Collection<A> annotations)
public <A extends Annotation, C extends BasicBrowser & BasicDataManager>
void unlink(C client, Collection<A> annotations)
throws ServiceException, AccessException, ExecutionException, InterruptedException {
removeLinks(client,
annotationLinkType(),
Expand All @@ -498,17 +501,17 @@ public <A extends Annotation> void unlink(Client client, Collection<A> annotatio
* @throws ExecutionException A Facility can't be retrieved or instantiated.
* @throws InterruptedException If block(long) does not return.
*/
protected void removeLinks(Client client, String linkType, Collection<Long> childIds)
protected <C extends BasicBrowser & BasicDataManager> void removeLinks(C client, String linkType,
Collection<Long> childIds)
throws ServiceException, AccessException, ExecutionException, InterruptedException {
String template = "select link from %s link" +
" where link.parent = %d" +
" and link.child.id in (:ids)";
String query = String.format(template, linkType, getId());
ParametersI param = new ParametersI();
param.addIds(childIds);
List<IObject> os = call(client.getGateway(),
g -> g.getQueryService(client.getCtx())
.findAllByQuery(query, param),
List<IObject> os = call(client.getQueryService(),
qs -> qs.findAllByQuery(query, param),
"Cannot get links from " + this);
client.delete(os);
}
Expand All @@ -526,7 +529,7 @@ protected void removeLinks(Client client, String linkType, Collection<Long> chil
* @throws ExecutionException A Facility can't be retrieved or instantiated.
* @throws InterruptedException If block(long) does not return.
*/
protected void removeLink(Client client, String linkType, long childId)
protected <C extends BasicBrowser & BasicDataManager> void removeLink(C client, String linkType, long childId)
throws ServiceException, AccessException, ExecutionException, InterruptedException {
removeLinks(client, linkType, singletonList(childId));
}
Expand Down
17 changes: 10 additions & 7 deletions src/main/java/fr/igred/omero/containers/Dataset.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
import fr.igred.omero.annotations.TagAnnotation;
import fr.igred.omero.client.BasicBrowser;
import fr.igred.omero.client.BasicDataManager;
import fr.igred.omero.client.Client;
import fr.igred.omero.client.ConnectionHandler;
import fr.igred.omero.client.DataManager;
import fr.igred.omero.core.Image;
import fr.igred.omero.core.ImageBrowser;
import fr.igred.omero.core.ImageWrapper;
Expand Down Expand Up @@ -353,7 +353,7 @@ default void addImage(BasicDataManager dm, Image image)
* @throws ExecutionException A Facility can't be retrieved or instantiated.
* @throws InterruptedException If block(long) does not return.
*/
void removeImage(Client client, Image image)
<C extends BasicBrowser & BasicDataManager> void removeImage(C client, Image image)
throws ServiceException, AccessException, ExecutionException, InterruptedException;


Expand Down Expand Up @@ -423,9 +423,10 @@ List<Long> importImage(ConnectionHandler conn, String path)
* @throws ExecutionException A Facility can't be retrieved or instantiated.
* @throws InterruptedException If block(long) does not return.
*/
default List<Image> replaceImages(Client client,
Collection<? extends Image> oldImages,
Image newImage)
default <C extends ContainersBrowser & BasicDataManager>
List<Image> replaceImages(C client,
Collection<? extends Image> oldImages,
Image newImage)
throws AccessException, ServiceException, ExecutionException, InterruptedException {
Collection<String> descriptions = new ArrayList<>(oldImages.size() + 1);
List<Image> orphaned = new ArrayList<>(oldImages.size());
Expand Down Expand Up @@ -468,7 +469,8 @@ default List<Image> replaceImages(Client client,
* @throws ExecutionException A Facility can't be retrieved or instantiated.
* @throws InterruptedException If block(long) does not return.
*/
List<Long> importAndReplaceImages(Client client, String path, ReplacePolicy policy)
<C extends ImageBrowser & DataManager & ConnectionHandler & ContainersBrowser>
List<Long> importAndReplaceImages(C client, String path, ReplacePolicy policy)
throws ServiceException, AccessException, IOException, ExecutionException, InterruptedException;


Expand All @@ -487,7 +489,8 @@ List<Long> importAndReplaceImages(Client client, String path, ReplacePolicy poli
* @throws ExecutionException A Facility can't be retrieved or instantiated.
* @throws InterruptedException If block(long) does not return.
*/
default List<Long> importAndReplaceImages(Client client, String path)
default <C extends ImageBrowser & DataManager & ConnectionHandler & ContainersBrowser>
List<Long> importAndReplaceImages(C client, String path)
throws ServiceException, AccessException, IOException, ExecutionException, InterruptedException {
return importAndReplaceImages(client, path, ReplacePolicy.UNLINK);
}
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/fr/igred/omero/containers/DatasetWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
import fr.igred.omero.RemoteObject;
import fr.igred.omero.RepositoryObjectWrapper;
import fr.igred.omero.client.BasicBrowser;
import fr.igred.omero.client.Client;
import fr.igred.omero.client.BasicDataManager;
import fr.igred.omero.client.ConnectionHandler;
import fr.igred.omero.client.DataManager;
import fr.igred.omero.core.Image;
import fr.igred.omero.core.ImageBrowser;
import fr.igred.omero.core.ImageWrapper;
import fr.igred.omero.exception.AccessException;
import fr.igred.omero.exception.ServiceException;
Expand Down Expand Up @@ -176,7 +178,8 @@ public List<Image> getImages(BasicBrowser browser)
* @throws InterruptedException If block(long) does not return.
*/
@Override
public void removeImage(Client client, Image image)
public <C extends BasicBrowser & BasicDataManager>
void removeImage(C client, Image image)
throws ServiceException, AccessException, ExecutionException, InterruptedException {
removeLink(client, "DatasetImageLink", image.getId());
}
Expand Down Expand Up @@ -238,7 +241,8 @@ public List<Long> importImage(ConnectionHandler conn, String path)
* @throws InterruptedException If block(long) does not return.
*/
@Override
public List<Long> importAndReplaceImages(Client client, String path, ReplacePolicy policy)
public <C extends ImageBrowser & DataManager & ConnectionHandler & ContainersBrowser>
List<Long> importAndReplaceImages(C client, String path, ReplacePolicy policy)
throws ServiceException, AccessException, IOException, ExecutionException, InterruptedException {
List<Long> ids = importImage(client, path);
Long[] newIds = ids.toArray(LONGS);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/fr/igred/omero/containers/Project.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import fr.igred.omero.annotations.TagAnnotation;
import fr.igred.omero.client.BasicBrowser;
import fr.igred.omero.client.BasicDataManager;
import fr.igred.omero.client.Client;
import fr.igred.omero.core.Image;
import fr.igred.omero.core.ImageBrowser;
import fr.igred.omero.exception.AccessException;
Expand Down Expand Up @@ -154,7 +153,8 @@ default Dataset addDataset(BasicDataManager dm, Dataset dataset)
* @throws ExecutionException A Facility can't be retrieved or instantiated.
* @throws InterruptedException If block(long) does not return.
*/
void removeDataset(Client client, Dataset dataset)
<C extends BasicBrowser & BasicDataManager>
void removeDataset(C client, Dataset dataset)
throws ServiceException, AccessException, ExecutionException, InterruptedException;


Expand Down
4 changes: 2 additions & 2 deletions src/main/java/fr/igred/omero/containers/ProjectWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import fr.igred.omero.RepositoryObjectWrapper;
import fr.igred.omero.client.BasicBrowser;
import fr.igred.omero.client.BasicDataManager;
import fr.igred.omero.client.Client;
import fr.igred.omero.core.Image;
import fr.igred.omero.core.ImageWrapper;
import fr.igred.omero.exception.AccessException;
Expand Down Expand Up @@ -178,7 +177,8 @@ public Dataset addDataset(BasicDataManager dm, String name, String description)
* @throws InterruptedException If block(long) does not return.
*/
@Override
public void removeDataset(Client client, Dataset dataset)
public <C extends BasicBrowser & BasicDataManager>
void removeDataset(C client, Dataset dataset)
throws ServiceException, AccessException, ExecutionException, InterruptedException {
removeLink(client, "ProjectDatasetLink", dataset.getId());
reload(client);
Expand Down
Loading

0 comments on commit 4eb1ba7

Please sign in to comment.