Skip to content

Commit

Permalink
Merge pull request #6 from sbesson/tests_repackage
Browse files Browse the repository at this point in the history
Generalize ZarrPixelsService.getUri to support additional entityType/entityId
  • Loading branch information
chris-allan authored May 8, 2024
2 parents a7d5f3b + f095710 commit e017eb1
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,29 @@ private Path asPath(String ngffDir) throws IOException {
return Paths.get(ngffDir);
}


/**
* Retrieve {@link Mask} or {@link Image} URI.
* Retrieve {@link Mask} or {@link Image} URI stored under {@link ExternalInfo}.
* @param object loaded {@link Mask} or {@link Image} to check for a URI
* @return URI or <code>null</code> if the object does not contain a URI
* in its {@link ExternalInfo}.
* @return the value of {@link ExternalInfo.lsid}, <code>null</code> if the object
* does not have an {@link ExternalInfo} with a valid {@link ExternalInfo.lsid} atttribute
* or if {@link ExternalInfo.entityType} is not equal to {@link NGFF_ENTITY_TYPE} or if
* {@link ExternalInfo.entityId} is not equal to {@link NGFF_ENTITY_ID}.
*/
public String getUri(IObject object) {
return getUri(object, NGFF_ENTITY_TYPE, NGFF_ENTITY_ID);
}

/**
* Retrieve {@link Mask} or {@link Image} URI stored under {@link ExternalInfo}
* @param object loaded {@link Mask} or {@link Image} to check for a URI
* @param targetEntityType expected entityType in the object {@link ExternalInfo}
* @param targetEntityId expected entityType in the object {@link ExternalInfo}
* @return the value of {@link ExternalInfo.lsid}, <code>null</code> if the object
* does not have an {@link ExternalInfo} with a valid {@link ExternalInfo.lsid} atttribute
* or if {@link ExternalInfo.entityType} is not equal to <code>targetEntityType</code> or if
* {@link ExternalInfo.entityId} is not equal to <code>targetEntityId</code> .
*/
public String getUri(IObject object, String targetEntityType, Long targetEntityId) {
ExternalInfo externalInfo = object.getDetails().getExternalInfo();
if (externalInfo == null) {
log.debug(
Expand All @@ -210,7 +225,7 @@ public String getUri(IObject object) {
object.getClass().getSimpleName(), object.getId());
return null;
}
if (!entityType.equals(NGFF_ENTITY_TYPE)) {
if (!entityType.equals(targetEntityType)) {
log.debug(
"{}:{} unsupported ExternalInfo entityType {}",
object.getClass().getSimpleName(), object.getId(), entityType);
Expand All @@ -224,7 +239,7 @@ public String getUri(IObject object) {
object.getClass().getSimpleName(), object.getId());
return null;
}
if (!entityId.equals(NGFF_ENTITY_ID)) {
if (!entityId.equals(targetEntityId)) {
log.debug(
"{}:{} unsupported ExternalInfo entityId {}",
object.getClass().getSimpleName(), object.getId(), entityId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

package com.glencoesoftware.omero.ms.core;
package com.glencoesoftware.omero.zarr;

import java.awt.Dimension;
import java.io.File;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

package com.glencoesoftware.omero.ms.core;
package com.glencoesoftware.omero.zarr;

import java.io.IOException;
import java.io.File;
Expand All @@ -43,16 +43,17 @@
import static omero.rtypes.rlong;
import static omero.rtypes.rstring;

public class PixelsServiceTest {
public class ZarrPixelsServiceTest {

private ZarrPixelsService pixelsService;
private String uuid = UUID.randomUUID().toString();
private String imageUri = "/data/ngff/image.zarr";
private String labelUri = imageUri + "/0/labels/" + uuid;
private Image image;
private Mask mask;
private ome.model.IObject object;
private String ENTITY_TYPE = "com.glencoesoftware.ngff:multiscales";
private int ENTITY_ID = 3;
private long ENTITY_ID = 3;

@Before
public void setUp() throws IOException {
Expand All @@ -66,7 +67,7 @@ public void setUp() throws IOException {
image = new ImageI();
}

private void addExternalInfo(IObject object, Integer entityId, String entityType, String lsid, String uuid) {
private void addExternalInfo(IObject object, Long entityId, String entityType, String lsid, String uuid) {
ExternalInfo externalInfo = new ExternalInfoI();
externalInfo.setEntityId(rlong(entityId));
externalInfo.setEntityType(rstring(entityType));
Expand All @@ -82,51 +83,80 @@ private void addExternalInfo(IObject object, Integer entityId, String entityType
@Test
public void testDefault() throws ApiUsageException, IOException {
addExternalInfo(mask, ENTITY_ID, ENTITY_TYPE, labelUri, uuid);
Assert.assertEquals(pixelsService.getUri((ome.model.roi.Mask) new IceMapper().reverse(mask)), labelUri);
object = (ome.model.roi.Mask) new IceMapper().reverse(mask);
Assert.assertEquals(pixelsService.getUri(object), labelUri);
Assert.assertEquals(pixelsService.getUri(object, ENTITY_TYPE, ENTITY_ID), labelUri);

addExternalInfo(image, ENTITY_ID, ENTITY_TYPE, imageUri, uuid);
Assert.assertEquals(pixelsService.getUri((ome.model.core.Image) new IceMapper().reverse(image)), imageUri);
object = (ome.model.core.Image) new IceMapper().reverse(image);
Assert.assertEquals(pixelsService.getUri(object), imageUri);
Assert.assertEquals(pixelsService.getUri(object, ENTITY_TYPE, ENTITY_ID), imageUri);
}

@Test
public void testGetUriNoExternalInfo() throws ApiUsageException, IOException {
Assert.assertNull(pixelsService.getUri((ome.model.roi.Mask) new IceMapper().reverse(mask)));
Assert.assertNull(pixelsService.getUri((ome.model.core.Image) new IceMapper().reverse(image)));
object = (ome.model.roi.Mask) new IceMapper().reverse(mask);
Assert.assertNull(pixelsService.getUri(object));
Assert.assertNull(pixelsService.getUri(object, ENTITY_TYPE, ENTITY_ID));

object = (ome.model.core.Image) new IceMapper().reverse(image);
Assert.assertNull(pixelsService.getUri(object));
Assert.assertNull(pixelsService.getUri(object, ENTITY_TYPE, ENTITY_ID));
}

@Test
public void testGetUriNoUuid() throws ApiUsageException, IOException {
addExternalInfo(mask, ENTITY_ID, ENTITY_TYPE, labelUri, null);
Assert.assertEquals(pixelsService.getUri((ome.model.roi.Mask) new IceMapper().reverse(mask)), labelUri);
object = (ome.model.roi.Mask) new IceMapper().reverse(mask);
Assert.assertEquals(pixelsService.getUri(object), labelUri);
Assert.assertEquals(pixelsService.getUri(object, ENTITY_TYPE, ENTITY_ID), labelUri);

addExternalInfo(image, ENTITY_ID, ENTITY_TYPE, imageUri, null);
Assert.assertEquals(pixelsService.getUri((ome.model.core.Image) new IceMapper().reverse(image)), imageUri);
object = (ome.model.core.Image) new IceMapper().reverse(image);
Assert.assertEquals(pixelsService.getUri(object), imageUri);
Assert.assertEquals(pixelsService.getUri(object, ENTITY_TYPE, ENTITY_ID), imageUri);
}

@Test
public void testGetUriNoLsid() throws ApiUsageException, IOException {
addExternalInfo(mask, ENTITY_ID, ENTITY_TYPE, null, uuid);
Assert.assertNull(pixelsService.getUri((ome.model.roi.Mask) new IceMapper().reverse(mask)));
object = (ome.model.roi.Mask) new IceMapper().reverse(mask);
Assert.assertNull(pixelsService.getUri(object));
Assert.assertNull(pixelsService.getUri(object, ENTITY_TYPE, ENTITY_ID));

addExternalInfo(image, ENTITY_ID, ENTITY_TYPE, null, uuid);
Assert.assertNull(pixelsService.getUri((ome.model.core.Image) new IceMapper().reverse(image)));
object = (ome.model.core.Image) new IceMapper().reverse(image);
Assert.assertNull(pixelsService.getUri(object));
Assert.assertNull(pixelsService.getUri(object, ENTITY_TYPE, ENTITY_ID));
}

@Test
public void testGetUriWrongEntityType() throws ApiUsageException, IOException {
addExternalInfo(mask, ENTITY_ID, "multiscales", labelUri, uuid);
Assert.assertNull(pixelsService.getUri((ome.model.roi.Mask) new IceMapper().reverse(mask)));
object = (ome.model.roi.Mask) new IceMapper().reverse(mask);
Assert.assertNull(pixelsService.getUri(object));
Assert.assertNull(pixelsService.getUri(object, ENTITY_TYPE, ENTITY_ID));
Assert.assertEquals(pixelsService.getUri(object, "multiscales", ENTITY_ID), labelUri);

addExternalInfo(image, ENTITY_ID, "multiscales", imageUri, uuid);
Assert.assertNull(pixelsService.getUri((ome.model.core.Image) new IceMapper().reverse(image)));
object = (ome.model.core.Image) new IceMapper().reverse(image);
Assert.assertNull(pixelsService.getUri(object));
Assert.assertNull(pixelsService.getUri(object, ENTITY_TYPE, ENTITY_ID));
Assert.assertEquals(pixelsService.getUri(object, "multiscales", ENTITY_ID), imageUri);
}

@Test
public void testGetUriWrongEntityId() throws ApiUsageException, IOException {
addExternalInfo(mask, 1, ENTITY_TYPE, labelUri, uuid);
Assert.assertNull(pixelsService.getUri((ome.model.roi.Mask) new IceMapper().reverse(mask)));

addExternalInfo(image, 1, ENTITY_TYPE, imageUri, uuid);
Assert.assertNull(pixelsService.getUri((ome.model.core.Image) new IceMapper().reverse(image)));
addExternalInfo(mask, 1L, ENTITY_TYPE, labelUri, uuid);
object = (ome.model.roi.Mask) new IceMapper().reverse(mask);
Assert.assertNull(pixelsService.getUri(object));
Assert.assertNull(pixelsService.getUri(object, ENTITY_TYPE, ENTITY_ID));
Assert.assertEquals(pixelsService.getUri(object, ENTITY_TYPE, 1L), labelUri);

addExternalInfo(image, 1L, ENTITY_TYPE, imageUri, uuid);
object = (ome.model.core.Image) new IceMapper().reverse(image);
Assert.assertNull(pixelsService.getUri(object));
Assert.assertNull(pixelsService.getUri(object, ENTITY_TYPE, ENTITY_ID));
Assert.assertEquals(pixelsService.getUri(object, ENTITY_TYPE, 1L), imageUri);
}
}

0 comments on commit e017eb1

Please sign in to comment.