Skip to content

Commit

Permalink
Add methods to delete multiple tables with one API call (#63)
Browse files Browse the repository at this point in the history
* Add methods to delete multiple tables with one API call
* Use Long array as argument to deleteFiles
* Improve tests
* Bump version

---------

Co-authored-by: Pierre Pouchin <[email protected]>
  • Loading branch information
Rdornier and ppouchin authored Jun 27, 2023
1 parent 3f0fa88 commit bea2171
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 19 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<groupId>fr.igred</groupId>
<artifactId>simple-omero-client</artifactId>
<version>5.13.1</version>
<version>5.14.0</version>
<packaging>jar</packaging>

<name>Simple OMERO Client</name>
Expand Down
38 changes: 37 additions & 1 deletion src/main/java/fr/igred/omero/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,24 @@ public void delete(GenericObjectWrapper<?> object)
}


/**
* @param table Table to delete.
*
* @throws ServiceException Cannot connect to OMERO.
* @throws AccessException Cannot access data.
* @throws ExecutionException A Facility can't be retrieved or instantiated.
* @throws IllegalArgumentException ID not defined.
* @throws OMEROServerError Server error.
* @throws InterruptedException If block(long) does not return.
* @deprecated Deletes a table from OMERO.
*/
@Deprecated
public void delete(TableWrapper table)
throws ServiceException, AccessException, ExecutionException, OMEROServerError, InterruptedException {
deleteTable(table);
}


/**
* Deletes a table from OMERO.
*
Expand All @@ -230,12 +248,30 @@ public void delete(GenericObjectWrapper<?> object)
* @throws OMEROServerError Server error.
* @throws InterruptedException If block(long) does not return.
*/
public void delete(TableWrapper table)
public void deleteTable(TableWrapper table)
throws ServiceException, AccessException, ExecutionException, OMEROServerError, InterruptedException {
deleteFile(table.getId());
}


/**
* Deletes tables from OMERO.
*
* @param tables List of tables to delete.
*
* @throws ServiceException Cannot connect to OMERO.
* @throws AccessException Cannot access data.
* @throws ExecutionException A Facility can't be retrieved or instantiated.
* @throws IllegalArgumentException ID not defined.
* @throws OMEROServerError Server error.
* @throws InterruptedException If block(long) does not return.
*/
public void deleteTables(Collection<? extends TableWrapper> tables)
throws ServiceException, AccessException, ExecutionException, OMEROServerError, InterruptedException {
deleteFiles(tables.stream().map(TableWrapper::getId).toArray(Long[]::new));
}


/**
* Returns the user which matches the username.
*
Expand Down
25 changes: 23 additions & 2 deletions src/main/java/fr/igred/omero/GatewayWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@
import omero.model.FileAnnotationI;
import omero.model.IObject;

import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Collectors;


/**
Expand Down Expand Up @@ -501,8 +503,27 @@ void delete(List<IObject> objects)
*/
public void deleteFile(Long id)
throws ServiceException, AccessException, ExecutionException, OMEROServerError, InterruptedException {
FileAnnotationI file = new FileAnnotationI(id, false);
delete(file);
deleteFiles(id);
}


/**
* Deletes files from OMERO.
*
* @param ids List of files IDs to delete.
*
* @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.
*/
public void deleteFiles(Long... ids)
throws ServiceException, AccessException, ExecutionException, OMEROServerError, InterruptedException {
List<IObject> files = Arrays.stream(ids)
.map(id -> new FileAnnotationI(id, false))
.collect(Collectors.toList());
delete(files);
}


Expand Down
28 changes: 14 additions & 14 deletions src/test/java/fr/igred/omero/annotations/ImageJTableTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ void testCreateTableWithROIsFromIJResults1() throws Exception {
long roiId = rois.get(0).getId();
Long fileId = table.getFileId();

client.delete(table);
client.deleteTable(table);

assertEquals(1, rowCount);
assertEquals(imageId, ((DataObject) data[0][0]).getId());
Expand Down Expand Up @@ -188,7 +188,7 @@ void testCreateTableWithROIsFromIJResults2() throws Exception {
long roiId = rois.get(0).getId();
Long fileId = table.getFileId();

client.delete(table);
client.deleteTable(table);

assertEquals(1, rowCount);
assertEquals(imageId, ((DataObject) data[0][0]).getId());
Expand Down Expand Up @@ -220,7 +220,7 @@ void testCreateTableWithROIsFromIJResults3() throws Exception {
long roiId = rois.get(0).getId();
Long fileId = table.getFileId();

client.delete(table);
client.deleteTable(table);

assertEquals(1, rowCount);
assertEquals(imageId, ((DataObject) data[0][0]).getId());
Expand Down Expand Up @@ -250,7 +250,7 @@ void testCreateTableWithROIsFromIJResults4() throws Exception {
long roiId = rois.get(0).getId();
Long fileId = table.getFileId();

client.delete(table);
client.deleteTable(table);

assertEquals(1, rowCount);
assertEquals(imageId, ((DataObject) data[0][0]).getId());
Expand Down Expand Up @@ -278,7 +278,7 @@ void testCreateTableFromIJResults() throws Exception {

Object[][] data = tables.get(0).getData();

client.delete(tables.get(0));
client.deleteTable(tables.get(0));
List<TableWrapper> noTables = image.getTables(client);

assertEquals(imageId, ((DataObject) data[0][0]).getId());
Expand Down Expand Up @@ -308,7 +308,7 @@ void testAddRowsFromIJResults() throws Exception {

Object[][] data = tables.get(0).getData();

client.delete(tables.get(0));
client.deleteTables(tables);
List<TableWrapper> noTables = image.getTables(client);

assertEquals(imageId, ((DataObject) data[0][0]).getId());
Expand Down Expand Up @@ -345,7 +345,7 @@ void testAddRowsWithROIsFromIJResults() throws Exception {
long roiId = rois.get(0).getId();
Long fileId = table.getFileId();

client.delete(table);
client.deleteTable(table);

assertEquals(2, rowCount);
assertEquals(imageId, ((DataObject) data[0][0]).getId());
Expand Down Expand Up @@ -385,7 +385,7 @@ void testCreateTableWithLocalROIFromIJResults1() throws Exception {
Object[][] data = table.getData();
Long fileId = table.getFileId();

client.delete(table);
client.deleteTable(table);

assertEquals(2, rowCount);
assertEquals(imageId, ((DataObject) data[0][0]).getId());
Expand Down Expand Up @@ -424,7 +424,7 @@ void testCreateTableWithLocalROIFromIJResults2() throws Exception {
Object[][] data = table.getData();
Long fileId = table.getFileId();

client.delete(table);
client.deleteTable(table);

assertEquals(2, rowCount);
assertEquals(imageId, ((DataObject) data[0][0]).getId());
Expand Down Expand Up @@ -477,7 +477,7 @@ void testCreateTableWithROINamesFromIJResults1() throws Exception {
Object[][] data = table.getData();
Long fileId = table.getFileId();

client.delete(table);
client.deleteTable(table);

assertEquals(2, rowCount);
assertEquals(imageId, ((DataObject) data[0][0]).getId());
Expand Down Expand Up @@ -535,7 +535,7 @@ void testCreateTableWithROINamesFromIJResults2() throws Exception {
Object[][] data = table.getData();
Long fileId = table.getFileId();

client.delete(table);
client.deleteTable(table);

assertEquals(2, rowCount);
assertEquals(imageId, ((DataObject) data[0][0]).getId());
Expand Down Expand Up @@ -596,7 +596,7 @@ void testNumberFormatException() throws Exception {
Object[][] data = table.getData();
Long fileId = table.getFileId();

client.delete(table);
client.deleteTable(table);

assertEquals(1, rowCount);
assertEquals(imageId, ((DataObject) data[0][0]).getId());
Expand Down Expand Up @@ -627,7 +627,7 @@ void testNumericName() throws Exception {
Object[][] data = table.getData();
Long fileId = table.getFileId();

client.delete(table);
client.deleteTable(table);

assertEquals(1, rowCount);
assertEquals(imageId, ((DataObject) data[0][0]).getId());
Expand Down Expand Up @@ -663,7 +663,7 @@ void testAddRowsFromIJResultsInverted() throws Exception {
assertEquals(1, tables.size());
assertEquals(2, tables.get(0).getRowCount());

client.delete(tables.get(0));
client.deleteTables(tables);
List<TableWrapper> noTables = image.getTables(client);

assertEquals(imageId, ((DataObject) data[0][0]).getId());
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/fr/igred/omero/annotations/TableTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void testCreateTable() throws Exception {
dataset.addTable(client, table);

List<TableWrapper> tables = dataset.getTables(client);
client.delete(tables.get(0));
client.deleteTables(tables);
List<TableWrapper> noTables = dataset.getTables(client);

assertEquals(1, tables.size());
Expand Down

0 comments on commit bea2171

Please sign in to comment.