Search in sources :

Example 1 with TablesFacility

use of omero.gateway.facility.TablesFacility in project imagej-omero by imagej.

the class DefaultOMEROService method uploadTable.

@Override
public long uploadTable(final OMEROCredentials credentials, final String name, final Table<?, ?> imageJTable, final long imageID) throws ServerError, PermissionDeniedException, CannotCreateSessionException, ExecutionException, DSOutOfServiceException, DSAccessException {
    final TableData omeroTable = convertOMEROTable(imageJTable);
    long id = -1;
    try (final OMEROSession session = new DefaultOMEROSession(credentials)) {
        // Get image
        final BrowseFacility browseFacility = session.getGateway().getFacility(BrowseFacility.class);
        final ImageData image = browseFacility.getImage(session.getSecurityContext(), imageID);
        // attach table to image
        final TablesFacility tablesFacility = session.getGateway().getFacility(TablesFacility.class);
        final TableData stored = tablesFacility.addTable(session.getSecurityContext(), image, name, omeroTable);
        id = stored.getOriginalFileId();
    }
    return id;
}
Also used : TablesFacility(omero.gateway.facility.TablesFacility) ImageData(omero.gateway.model.ImageData) TableData(omero.gateway.model.TableData) BrowseFacility(omero.gateway.facility.BrowseFacility)

Example 2 with TablesFacility

use of omero.gateway.facility.TablesFacility in project imagej-omero by imagej.

the class OmeroIT method testUploadTable.

@Test
public void testUploadTable() throws ServerError, PermissionDeniedException, CannotCreateSessionException, ExecutionException, DSOutOfServiceException, DSAccessException {
    final byte[][] d = new byte[][] { { 127, 0, -128 }, { -1, -6, -23 }, { 100, 87, 4 } };
    final ByteTable table = new DefaultByteTable(3, 3);
    for (int c = 0; c < table.getColumnCount(); c++) {
        table.setColumnHeader(c, "Heading " + (c + 1));
        for (int r = 0; r < table.getRowCount(); r++) table.set(c, r, d[c][r]);
    }
    final long tableId = omero.uploadTable(cred, "test-table-upload", table, 1);
    // When upload table was called it created a session, which cleared out
    // the username and password from the credentials. The credentials must
    // have a username and password to create security contexts.
    final OMEROCredentials tc = new OMEROCredentials();
    tc.setServer(OMERO_SERVER);
    tc.setPort(OMERO_PORT);
    tc.setUser(OMERO_USER);
    tc.setPassword(OMERO_PASSWORD);
    try (final OMEROSession session = new DefaultOMEROSession(tc)) {
        final TablesFacility tablesFacility = session.getGateway().getFacility(TablesFacility.class);
        final TableData td = tablesFacility.getTableInfo(session.getSecurityContext(), tableId);
        assertEquals(td.getColumns().length, 3);
        assertEquals(td.getColumns()[0].getName(), "Heading 1");
        assertEquals(td.getColumns()[1].getName(), "Heading 2");
        assertEquals(td.getColumns()[2].getName(), "Heading 3");
        assertEquals(td.getNumberOfRows(), 3);
    }
}
Also used : TablesFacility(omero.gateway.facility.TablesFacility) DefaultByteTable(net.imagej.table.DefaultByteTable) DefaultOMEROSession(net.imagej.omero.DefaultOMEROSession) ByteTable(net.imagej.table.ByteTable) DefaultByteTable(net.imagej.table.DefaultByteTable) OMEROSession(net.imagej.omero.OMEROSession) DefaultOMEROSession(net.imagej.omero.DefaultOMEROSession) TableData(omero.gateway.model.TableData) OMEROCredentials(net.imagej.omero.OMEROCredentials) Test(org.junit.Test)

Example 3 with TablesFacility

use of omero.gateway.facility.TablesFacility 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 4 with TablesFacility

use of omero.gateway.facility.TablesFacility 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)

Aggregations

TablesFacility (omero.gateway.facility.TablesFacility)4 TableData (omero.gateway.model.TableData)4 DefaultOMEROSession (net.imagej.omero.DefaultOMEROSession)1 OMEROCredentials (net.imagej.omero.OMEROCredentials)1 OMEROSession (net.imagej.omero.OMEROSession)1 ByteTable (net.imagej.table.ByteTable)1 DefaultByteTable (net.imagej.table.DefaultByteTable)1 GenericTable (net.imagej.table.GenericTable)1 BrowseFacility (omero.gateway.facility.BrowseFacility)1 FileAnnotationData (omero.gateway.model.FileAnnotationData)1 ImageData (omero.gateway.model.ImageData)1 TableDataColumn (omero.gateway.model.TableDataColumn)1 FileAnnotation (omero.model.FileAnnotation)1 FileAnnotationI (omero.model.FileAnnotationI)1 OriginalFile (omero.model.OriginalFile)1 OriginalFileI (omero.model.OriginalFileI)1 Test (org.junit.Test)1