Skip to content

Commit

Permalink
Merge pull request #85 from GReD-Clermont/small-fixes
Browse files Browse the repository at this point in the history
Small fixes
  • Loading branch information
ppouchin authored Feb 23, 2024
2 parents 892500a + 97806f9 commit adb96cc
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 30 deletions.
13 changes: 8 additions & 5 deletions src/main/java/fr/igred/omero/AnnotatableWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -552,19 +552,21 @@ public void addMapAnnotation(Client client, MapAnnotationWrapper mapAnnotation)
*/
public void addTable(Client client, TableWrapper table)
throws ServiceException, AccessException, ExecutionException {
String error = "Cannot add table to " + this;

TablesFacility tablesFacility = client.getTablesFacility();
TableData tableData = ExceptionHandler.of(tablesFacility,
tf -> tf.addTable(client.getCtx(),
data,
table.getName(),
table.createTable()))
.handleOMEROException("Cannot add table to " + this)
.handleOMEROException(error)
.get();

Collection<FileAnnotationData> tables = ExceptionHandler.of(tablesFacility,
tf -> tf.getAvailableTables(client.getCtx(),
data))
.handleOMEROException("Cannot add table to " + this)
.handleOMEROException(error)
.get();
long fileId = tableData.getOriginalFileId();

Expand All @@ -590,17 +592,18 @@ public void addTable(Client client, TableWrapper table)
*/
public void addAndReplaceTable(Client client, TableWrapper table, ReplacePolicy policy)
throws ServiceException, AccessException, ExecutionException, OMEROServerError, InterruptedException {
String error = "Cannot add table to " + this;

Collection<FileAnnotationWrapper> tables = wrap(ExceptionHandler.of(client.getTablesFacility(),
t -> t.getAvailableTables(
client.getCtx(), data))
.handleOMEROException("Cannot get tables from "
+ this)
.handleOMEROException(error)
.get(),
FileAnnotationWrapper::new);
addTable(client, table);
tables.removeIf(t -> !t.getDescription().equals(table.getName()));
this.unlink(client, tables);
for (FileAnnotationWrapper fileAnnotation : tables) {
this.unlink(client, fileAnnotation);
if (policy == ReplacePolicy.DELETE ||
policy == ReplacePolicy.DELETE_ORPHANED && fileAnnotation.countAnnotationLinks(client) == 0) {
client.deleteFile(fileAnnotation.getId());
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/fr/igred/omero/Browser.java
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,8 @@ public List<ImageWrapper> getImages(String name)
/**
* Gets all orphaned images owned by the specified user.
*
* @param experimenter The user.
*
* @return See above.
*
* @throws ServiceException Cannot connect to OMERO.
Expand Down
19 changes: 0 additions & 19 deletions src/main/java/fr/igred/omero/GenericObjectWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import fr.igred.omero.exception.AccessException;
import fr.igred.omero.exception.ExceptionHandler;
import fr.igred.omero.exception.OMEROServerError;
import fr.igred.omero.exception.ServiceException;
import fr.igred.omero.meta.ExperimenterWrapper;
import omero.gateway.model.DataObject;
Expand Down Expand Up @@ -93,24 +92,6 @@ protected GenericObjectWrapper(T o) {
}


/**
* Deletes an object from OMERO.
*
* @param client The client handling the connection.
* @param object The OMERO object.
*
* @throws ServiceException Cannot connect to OMERO.
* @throws AccessException Cannot access data.
* @throws ExecutionException A Facility can't be retrieved or instantiated.
* @throws OMEROServerError Server error.
* @throws InterruptedException If block(long) does not return.
*/
protected static void delete(Client client, IObject object)
throws ServiceException, AccessException, ExecutionException, OMEROServerError, InterruptedException {
client.delete(object);
}


/**
* Only keeps objects with different IDs in a collection.
*
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/fr/igred/omero/repository/ImageWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ public class ImageWrapper extends GenericRepositoryObjectWrapper<ImageData> {
/** Annotation link name for this type of object */
public static final String ANNOTATION_LINK = "ImageAnnotationLink";

/** Default IJ property to store image ID. */
public static final String IJ_ID_PROPERTY = "IMAGE_ID";


/**
* Constructor of the class ImageWrapper
Expand Down Expand Up @@ -771,7 +774,7 @@ public ImagePlus toImagePlus(Client client,
}
imp.setPosition(1);
if (IJ.getVersion().compareTo("1.53a") >= 0) {
imp.setProp("IMAGE_ID", getId());
imp.setProp(IJ_ID_PROPERTY, getId());
}
return imp;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/fr/igred/omero/roi/GenericShapeWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public abstract class GenericShapeWrapper<T extends ShapeData> extends Annotatab
public static final String ANNOTATION_LINK = "ShapeAnnotationLink";

/** Default IJ property to store shape ID. */
public static final String IJ_IDPROPERTY = "SHAPE_ID";
public static final String IJ_ID_PROPERTY = "SHAPE_ID";

/** Transparent color */
private static final Color TRANSPARENT = new Color(0, 0, 0, 0);
Expand Down Expand Up @@ -272,7 +272,7 @@ protected void copyToIJRoi(ij.gui.Roi ijRoi) {
if (ijRoi instanceof TextRoi) {
copyToIJTextRoi((TextRoi) ijRoi);
}
ijRoi.setProperty(IJ_IDPROPERTY, String.valueOf(data.getId()));
ijRoi.setProperty(IJ_ID_PROPERTY, String.valueOf(data.getId()));
}


Expand Down
4 changes: 2 additions & 2 deletions src/main/java/fr/igred/omero/roi/ROIWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ public static List<ij.gui.Roi> toImageJ(Collection<? extends ROIWrapper> rois, S
* @return See above.
*/
private static ij.gui.Roi xor(Collection<? extends ij.gui.Roi> rois) {
String idProperty = GenericShapeWrapper.IJ_IDPROPERTY;
String idProperty = GenericShapeWrapper.IJ_ID_PROPERTY;
String shapeIDs = rois.stream()
.map(r -> r.getProperty(idProperty))
.collect(Collectors.joining(","));
Expand Down Expand Up @@ -317,7 +317,7 @@ private static ij.gui.Roi xor(Collection<? extends ij.gui.Roi> rois) {
* @return See above.
*/
private static PointRoi combine(Collection<? extends PointRoi> points) {
String idProperty = GenericShapeWrapper.IJ_IDPROPERTY;
String idProperty = GenericShapeWrapper.IJ_ID_PROPERTY;
String shapeIDs = points.stream()
.map(p -> p.getProperty(idProperty))
.collect(Collectors.joining(","));
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/fr/igred/omero/repository/ImageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ void testToImagePlus() throws Exception {
ImageStatistics stats = difference.getStatistics();

assertEquals(0, (int) stats.max);
assertEquals(String.valueOf(IMAGE2.id), imp.getProp("IMAGE_ID"));
assertEquals(String.valueOf(IMAGE2.id), imp.getProp(ImageWrapper.IJ_ID_PROPERTY));
}


Expand Down

0 comments on commit adb96cc

Please sign in to comment.