Search in sources :

Example 11 with TableData

use of omero.gateway.model.TableData in project imagej-omero by imagej.

the class DefaultOMEROService method convertOMEROTable.

@Override
public TableData convertOMEROTable(final Table<?, ?> imageJTable) {
    final TableDataColumn[] omeroColumns = new TableDataColumn[imageJTable.getColumnCount()];
    final Object[][] data = new Object[imageJTable.getColumnCount()][];
    for (int c = 0; c < imageJTable.getColumnCount(); c++) {
        omeroColumns[c] = TableUtils.createOMEROColumn(imageJTable.get(c), c);
        data[c] = TableUtils.populateOMEROColumn(imageJTable.get(c), convertService);
    }
    // Create table and attach to image
    final TableData omeroTable = new TableData(omeroColumns, data);
    omeroTable.setNumberOfRows(imageJTable.getRowCount());
    return omeroTable;
}
Also used : TableDataColumn(omero.gateway.model.TableDataColumn) TableData(omero.gateway.model.TableData)

Example 12 with TableData

use of omero.gateway.model.TableData in project imagej-omero by imagej.

the class DefaultOMEROService method downloadTable.

@Override
public Table<?, ?> downloadTable(final OMEROCredentials credentials, final long tableID) throws ServerError, PermissionDeniedException, CannotCreateSessionException, ExecutionException, DSOutOfServiceException, DSAccessException {
    try (final OMEROSession session = new DefaultOMEROSession(credentials)) {
        final TablesFacility tableService = session.getGateway().getFacility(TablesFacility.class);
        final TableData table = tableService.getTable(session.getSecurityContext(), tableID, 0, Integer.MAX_VALUE - 1);
        final TableDataColumn[] omeroColumns = table.getColumns();
        final Object[][] data = table.getData();
        final Table<?, ?> imageJTable = TableUtils.createImageJTable(omeroColumns);
        imageJTable.setRowCount((int) table.getNumberOfRows());
        boolean colsCreated = false;
        if (!(imageJTable instanceof GenericTable)) {
            imageJTable.appendColumns(omeroColumns.length);
            colsCreated = true;
        }
        for (int i = 0; i < omeroColumns.length; i++) {
            if (!colsCreated) {
                final Column<?> imageJCol = TableUtils.createImageJColumn(omeroColumns[i]);
                TableUtils.populateImageJColumn(omeroColumns[i].getType(), data[omeroColumns[i].getIndex()], imageJCol);
                ((GenericTable) imageJTable).add(omeroColumns[i].getIndex(), imageJCol);
            } else {
                TableUtils.populateImageJColumn(omeroColumns[i].getType(), data[omeroColumns[i].getIndex()], imageJTable.get(i));
                imageJTable.get(i).setHeader(omeroColumns[i].getName());
            }
        }
        return imageJTable;
    }
}
Also used : TablesFacility(omero.gateway.facility.TablesFacility) GenericTable(net.imagej.table.GenericTable) TableDataColumn(omero.gateway.model.TableDataColumn) TableData(omero.gateway.model.TableData)

Example 13 with TableData

use of omero.gateway.model.TableData in project imagej-omero by imagej.

the class ModuleAdapter method attachTablesToImages.

/**
 * Attaches the tables to the input images. This also adds the Table ids to
 * the omero client.
 */
private void attachTablesToImages(final List<ImageData> images, final HashMap<String, TableData> tables, final SecurityContext ctx, final DataManagerFacility dm) throws DSOutOfServiceException, DSAccessException, ExecutionException, ServerError {
    final TablesFacility tablesFacility = gateway.getFacility(TablesFacility.class);
    for (final String name : tables.keySet()) {
        final TableData t = tablesFacility.addTable(ctx, images.get(0), name, tables.get(name));
        client.setOutput(name, omero.rtypes.rlong(t.getOriginalFileId()));
    }
    // Adding tables again would create new tables on the server
    for (int i = 1; i < images.size(); i++) {
        for (final String name : tables.keySet()) {
            final OriginalFile file = new OriginalFileI(tables.get(name).getOriginalFileId(), false);
            final FileAnnotation anno = new FileAnnotationI();
            anno.setFile(file);
            FileAnnotationData annotation = new FileAnnotationData(anno);
            annotation.setDescription(name);
            annotation = (FileAnnotationData) dm.saveAndReturnObject(ctx, annotation);
            dm.attachAnnotation(ctx, annotation, images.get(i));
        }
    }
}
Also used : TablesFacility(omero.gateway.facility.TablesFacility) FileAnnotationI(omero.model.FileAnnotationI) OriginalFileI(omero.model.OriginalFileI) FileAnnotation(omero.model.FileAnnotation) TableData(omero.gateway.model.TableData) OriginalFile(omero.model.OriginalFile) FileAnnotationData(omero.gateway.model.FileAnnotationData)

Example 14 with TableData

use of omero.gateway.model.TableData in project imagej-omero by imagej.

the class UploadTableTest method setUpMethodCalls.

// -- Helper methods --
private void setUpMethodCalls() throws ServerError, PermissionDeniedException, CannotCreateSessionException, DSOutOfServiceException, ExecutionException, DSAccessException {
    new Expectations() {

        {
            new DefaultOMEROSession(credentials);
            gateway.getFacility(BrowseFacility.class);
            result = browseFacility;
            browseFacility.getImage((SecurityContext) any, anyLong);
            result = new ImageData();
            gateway.getFacility(TablesFacility.class);
            result = tablesFacility;
            tablesFacility.addTable((SecurityContext) any, (ImageData) any, anyString, (TableData) any);
            result = new TableData((TableDataColumn[]) any, (Object[][]) any);
        }
    };
}
Also used : Expectations(mockit.Expectations) ImageData(omero.gateway.model.ImageData) DataObject(omero.gateway.model.DataObject) TableData(omero.gateway.model.TableData)

Example 15 with TableData

use of omero.gateway.model.TableData in project imagej-omero by imagej.

the class UploadTableTest method testBoolTable.

@Test
public void testBoolTable() throws ServerError, PermissionDeniedException, CannotCreateSessionException, ExecutionException, DSOutOfServiceException, DSAccessException {
    final BoolTable table = new DefaultBoolTable(2, 4);
    table.get(0).fill(new boolean[] { true, true, false, false });
    table.get(1).fill(new boolean[] { true, false, true, false });
    // Create expectations
    setUpMethodCalls();
    final long id = service.uploadTable(credentials, "table", table, 0);
    assertEquals(id, -1);
    // NB: Can only capture in a Verifications block
    new Verifications() {

        {
            TableData td;
            tablesFacility.addTable((SecurityContext) any, (ImageData) any, anyString, td = withCapture());
            tableEquals(table, td, Boolean.class);
        }
    };
}
Also used : BoolTable(net.imagej.table.BoolTable) DefaultBoolTable(net.imagej.table.DefaultBoolTable) DefaultBoolTable(net.imagej.table.DefaultBoolTable) Verifications(mockit.Verifications) TableData(omero.gateway.model.TableData) Test(org.junit.Test)

Aggregations

TableData (omero.gateway.model.TableData)23 Test (org.junit.Test)17 Verifications (mockit.Verifications)9 GenericTable (net.imagej.table.GenericTable)9 TableDataColumn (omero.gateway.model.TableDataColumn)9 DefaultColumn (net.imagej.table.DefaultColumn)6 DefaultGenericTable (net.imagej.table.DefaultGenericTable)4 TablesFacility (omero.gateway.facility.TablesFacility)4 ImageData (omero.gateway.model.ImageData)3 BoolColumn (net.imagej.table.BoolColumn)2 BoolTable (net.imagej.table.BoolTable)2 LongTable (net.imagej.table.LongTable)2 DataObject (omero.gateway.model.DataObject)2 DoubleArray (org.scijava.util.DoubleArray)2 HashMap (java.util.HashMap)1 Expectations (mockit.Expectations)1 DefaultOMEROSession (net.imagej.omero.DefaultOMEROSession)1 OMEROCredentials (net.imagej.omero.OMEROCredentials)1 OMEROSession (net.imagej.omero.OMEROSession)1 ByteTable (net.imagej.table.ByteTable)1